v5stable
Ondřej Hruška 10 years ago
parent 7d61de7c61
commit f81c349d20
  1. 9
      src/mightypork/gamecore/audio/DeferredAudio.java
  2. 3
      src/mightypork/gamecore/audio/NullAudio.java
  3. 8
      src/mightypork/gamecore/audio/SoundBank.java
  4. 45
      src/mightypork/gamecore/audio/SoundSystem.java
  5. 8
      src/mightypork/gamecore/audio/Volume.java
  6. 40
      src/mightypork/gamecore/audio/players/BaseAudioPlayer.java
  7. 36
      src/mightypork/gamecore/audio/players/EffectPlayer.java
  8. 37
      src/mightypork/gamecore/audio/players/LoopPlayer.java
  9. 5
      src/mightypork/gamecore/control/AppAdapter.java
  10. 7
      src/mightypork/gamecore/control/AppModule.java
  11. 11
      src/mightypork/gamecore/control/AppSubModule.java
  12. 64
      src/mightypork/gamecore/control/BaseApp.java
  13. 9
      src/mightypork/gamecore/control/GameLoop.java
  14. 3
      src/mightypork/gamecore/control/SlickLogRedirector.java
  15. 19
      src/mightypork/gamecore/control/bus/BufferedHashSet.java
  16. 7
      src/mightypork/gamecore/control/bus/EventBus.java
  17. 3
      src/mightypork/gamecore/control/bus/clients/BusNode.java
  18. 3
      src/mightypork/gamecore/control/bus/clients/RootBusNode.java
  19. 10
      src/mightypork/gamecore/control/bus/events/KeyEvent.java
  20. 8
      src/mightypork/gamecore/control/bus/events/MainLoopTaskRequest.java
  21. 5
      src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java
  22. 9
      src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java
  23. 10
      src/mightypork/gamecore/control/bus/events/ResourceLoadRequest.java
  24. 24
      src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java
  25. 11
      src/mightypork/gamecore/control/bus/events/ScreenRequestEvent.java
  26. 6
      src/mightypork/gamecore/control/interf/NoImpl.java
  27. 5
      src/mightypork/gamecore/control/timing/Pauseable.java
  28. 5
      src/mightypork/gamecore/gui/ActionTrigger.java
  29. 17
      src/mightypork/gamecore/gui/renderers/ColumnHolder.java
  30. 7
      src/mightypork/gamecore/gui/renderers/ElementHolder.java
  31. 11
      src/mightypork/gamecore/gui/renderers/ImagePainter.java
  32. 5
      src/mightypork/gamecore/gui/renderers/PluggableRenderable.java
  33. 17
      src/mightypork/gamecore/gui/renderers/RowHolder.java
  34. 77
      src/mightypork/gamecore/gui/renderers/TextPainter.java
  35. 8
      src/mightypork/gamecore/gui/screens/LayeredScreen.java
  36. 3
      src/mightypork/gamecore/gui/screens/Screen.java
  37. 6
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  38. 3
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  39. 8
      src/mightypork/gamecore/input/InputSystem.java
  40. 10
      src/mightypork/gamecore/input/KeyBinder.java
  41. 10
      src/mightypork/gamecore/loading/AsyncResourceLoader.java
  42. 4
      src/mightypork/gamecore/loading/BaseDeferredResource.java
  43. 34
      src/mightypork/gamecore/render/DisplaySystem.java
  44. 14
      src/mightypork/gamecore/render/Render.java
  45. 19
      src/mightypork/gamecore/render/Screenshot.java
  46. 3
      src/mightypork/gamecore/render/fonts/FontBank.java
  47. 5
      src/mightypork/gamecore/render/fonts/GLFont.java
  48. 5
      src/mightypork/gamecore/render/fonts/SlickFont.java
  49. 17
      src/mightypork/gamecore/render/textures/DeferredTexture.java
  50. 5
      src/mightypork/gamecore/render/textures/FilterMode.java
  51. 5
      src/mightypork/gamecore/render/textures/FilteredTexture.java
  52. 3
      src/mightypork/gamecore/render/textures/TextureBank.java
  53. 10
      src/mightypork/gamecore/render/textures/TxQuad.java
  54. 5
      src/mightypork/gamecore/render/textures/WrapMode.java
  55. 6
      src/mightypork/rogue/App.java
  56. 7
      src/mightypork/utils/math/animation/AnimDouble.java
  57. 7
      src/mightypork/utils/math/constraints/ContextAdapter.java
  58. 8
      src/mightypork/utils/math/constraints/NumberConstraint.java
  59. 8
      src/mightypork/utils/math/constraints/PluggableContext.java

@ -108,6 +108,9 @@ public class DeferredAudio extends BaseDeferredResource {
}
/**
* Stop playing
*/
public void stop()
{
if (!isLoaded()) return;
@ -117,6 +120,9 @@ public class DeferredAudio extends BaseDeferredResource {
}
/**
* @return true if the audio is playing
*/
public boolean isPlaying()
{
if (!isLoaded()) return false;
@ -125,6 +131,9 @@ public class DeferredAudio extends BaseDeferredResource {
}
/**
* @return trie if the audio is paused
*/
public boolean isPaused()
{
if (!isLoaded()) return false;

@ -14,6 +14,9 @@ import mightypork.utils.logging.LoggedName;
@LoggedName(name = "NullAudio")
public class NullAudio extends DeferredAudio implements NullResource {
/**
* new null audio
*/
public NullAudio() {
super(null);
}

@ -11,6 +11,11 @@ import mightypork.gamecore.control.AppAdapter;
import mightypork.utils.logging.Log;
/**
* Audio resource storage
*
* @author MightyPork
*/
public class SoundBank extends AppAdapter {
private static final DeferredAudio NO_SOUND = new NullAudio();
@ -21,6 +26,9 @@ public class SoundBank extends AppAdapter {
private final Map<String, LoopPlayer> loops = new HashMap<>();
/**
* @param app app access
*/
public SoundBank(AppAccess app) {
super(app);
if (getSoundSystem() == null) throw new NullPointerException("SoundSystem cannot be null.");

@ -63,6 +63,9 @@ public class SoundSystem extends RootBusNode implements Updateable {
}
/**
* @return listener coordinate
*/
public static Coord getListener()
{
return listener;
@ -70,14 +73,17 @@ public class SoundSystem extends RootBusNode implements Updateable {
// -- instance --
public final Volume masterVolume = new Volume(1D);
public final Volume effectsVolume = new JointVolume(masterVolume);
public final Volume loopsVolume = new JointVolume(masterVolume);
private final Volume masterVolume = new Volume(1D);
private final Volume effectsVolume = new JointVolume(masterVolume);
private final Volume loopsVolume = new JointVolume(masterVolume);
private final Set<LoopPlayer> loopPlayers = new HashSet<>();
private final Set<DeferredAudio> resources = new HashSet<>();
/**
* @param app app access
*/
public SoundSystem(AppAccess app) {
super(app);
}
@ -208,4 +214,37 @@ public class SoundSystem extends RootBusNode implements Updateable {
{
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();
}
}

@ -5,8 +5,16 @@ import mightypork.utils.math.Calc;
import mightypork.utils.objects.Mutable;
/**
* Mutable volume 0-1
*
* @author MightyPork
*/
public class Volume extends Mutable<Double> {
/**
* @param d initial value
*/
public Volume(Double d) {
super(d);
}

@ -6,6 +6,11 @@ import mightypork.gamecore.audio.Volume;
import mightypork.gamecore.control.interf.Destroyable;
/**
* Basic abstract player
*
* @author MightyPork
*/
public abstract class BaseAudioPlayer implements Destroyable {
/** the track */
@ -21,20 +26,21 @@ public abstract class BaseAudioPlayer implements Destroyable {
private final Volume gainMultiplier;
public BaseAudioPlayer(DeferredAudio track, double baseGain, Volume gainMultiplier) {
this(track, 1, baseGain, gainMultiplier);
}
public BaseAudioPlayer(DeferredAudio track, double basePitch, double baseGain, Volume gainMultiplier) {
/**
* @param track audio resource
* @param basePitch base pitch (pitch multiplier)
* @param baseGain base gain (volume multiplier)
* @param volume colume control
*/
public BaseAudioPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume) {
this.audio = track;
this.baseGain = baseGain;
this.basePitch = basePitch;
if (gainMultiplier == null) gainMultiplier = new Volume(1D);
if (volume == null) volume = new Volume(1D);
this.gainMultiplier = gainMultiplier;
this.gainMultiplier = volume;
}
@ -45,18 +51,33 @@ public abstract class BaseAudioPlayer implements Destroyable {
}
/**
* @return audio resource
*/
protected DeferredAudio getAudio()
{
return audio;
}
/**
* Get play gain, computed based on volume and given multiplier
*
* @param multiplier extra volume adjustment
* @return computed gain
*/
protected double getGain(double multiplier)
{
return baseGain * gainMultiplier.get() * multiplier;
}
/**
* Get pitch
*
* @param multiplier pitch adjustment
* @return computed pitch
*/
protected double getPitch(double multiplier)
{
return basePitch * multiplier;
@ -74,6 +95,9 @@ public abstract class BaseAudioPlayer implements Destroyable {
}
/**
* force load the resource
*/
public void load()
{
if (hasAudio()) audio.load();

@ -6,13 +6,31 @@ import mightypork.gamecore.audio.Volume;
import mightypork.utils.math.coord.Coord;
/**
* Player for one-off effects
*
* @author MightyPork
*/
public class EffectPlayer extends BaseAudioPlayer {
public EffectPlayer(DeferredAudio track, double basePitch, double baseGain, Volume gainMultiplier) {
super(track, (float) basePitch, (float) baseGain, gainMultiplier);
/**
* @param track audio resource
* @param basePitch base pitch (pitch multiplier)
* @param baseGain base gain (volume multiplier)
* @param volume volume control
*/
public EffectPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume) {
super(track, (float) basePitch, (float) baseGain, volume);
}
/**
* Play at listener
*
* @param pitch play pitch
* @param gain play gain
* @return source id
*/
public int play(double pitch, double gain)
{
if (!hasAudio()) return -1;
@ -21,12 +39,26 @@ public class EffectPlayer extends BaseAudioPlayer {
}
/**
* Play at listener
*
* @param gain play gain
* @return source id
*/
public int play(double gain)
{
return play(1, gain);
}
/**
* Play at given position
*
* @param pitch play pitch
* @param gain play gain
* @param pos play position
* @return source id
*/
public int play(double pitch, double gain, Coord pos)
{
if (!hasAudio()) return -1;

@ -10,6 +10,11 @@ import mightypork.utils.math.animation.AnimDouble;
import org.lwjgl.openal.AL10;
/**
* Audio loop player (with fading, good for music)
*
* @author MightyPork
*/
public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable {
private int sourceID = -1;
@ -29,13 +34,25 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable
private double outTime = 1;
public LoopPlayer(DeferredAudio track, double pitch, double baseGain, Volume gainMultiplier) {
super(track, (float) pitch, (float) baseGain, gainMultiplier);
/**
* @param track audio resource
* @param basePitch base pitch (pitch multiplier)
* @param baseGain base gain (volume multiplier)
* @param volume volume control
*/
public LoopPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume) {
super(track, (float) basePitch, (float) baseGain, volume);
paused = true;
}
/**
* Set fading duration (seconds)
*
* @param in duration of fade-in
* @param out duration of fade-out
*/
public void setFadeTimes(double in, double out)
{
inTime = in;
@ -102,6 +119,11 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable
}
/**
* Resume if paused, and fade in (pick up from current volume).
*
* @param secs
*/
public void fadeIn(double secs)
{
if (!hasAudio()) return;
@ -111,6 +133,11 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable
}
/**
* Fade out and pause when reached zero volume
*
* @param secs fade duration
*/
public void fadeOut(double secs)
{
if (!hasAudio()) return;
@ -119,12 +146,18 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable
}
/**
* Fade in with default duration
*/
public void fadeIn()
{
fadeIn(inTime);
}
/**
* Fade out with default duration
*/
public void fadeOut()
{
fadeOut(outTime);

@ -8,7 +8,7 @@ import mightypork.gamecore.render.DisplaySystem;
/**
* App access adapter
* App access adapter (defualt {@link AppAccess} implementation)
*
* @author MightyPork
*/
@ -17,6 +17,9 @@ public class AppAdapter implements AppAccess {
private final AppAccess app;
/**
* @param app app access
*/
public AppAdapter(AppAccess app) {
if (app == null) throw new NullPointerException("AppAccess instance cannot be null.");

@ -9,7 +9,7 @@ import mightypork.gamecore.render.DisplaySystem;
/**
* App event bus client, to be used for subsystems, screens and anything that
* needs access to the eventbus
* needs access to the eventbus and other systems; Attached directly to bus.
*
* @author MightyPork
*/
@ -18,6 +18,11 @@ public abstract class AppModule extends RootBusNode implements AppAccess {
private final AppAccess app;
/**
* Create a module
*
* @param app access to app systems
*/
public AppModule(AppAccess app) {
super(app);

@ -3,13 +3,15 @@ package mightypork.gamecore.control;
import mightypork.gamecore.audio.SoundSystem;
import mightypork.gamecore.control.bus.clients.BusNode;
import mightypork.gamecore.control.bus.clients.DelegatingClient;
import mightypork.gamecore.control.bus.clients.RootBusNode;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.render.DisplaySystem;
/**
* App event bus client, to be used for subsystems, screens and anything that
* needs access to the eventbus
* Delegating bus client, to be attached to any {@link DelegatingClient}, such
* as a {@link RootBusNode}.
*
* @author MightyPork
*/
@ -18,6 +20,11 @@ public abstract class AppSubModule extends BusNode implements AppAccess {
private final AppAccess app;
/**
* Create submodule
*
* @param app access to app systems
*/
public AppSubModule(AppAccess app) {
super(app);

@ -52,15 +52,20 @@ public abstract class BaseApp implements AppAccess {
}
/**
* Init the app
*/
protected void initialize()
{
preInit();
/*
* Lock working directory
*/
initLock();
// hook
preInit();
/*
* Setup logging
*/
@ -77,7 +82,7 @@ public abstract class BaseApp implements AppAccess {
eventBus = new EventBus();
Log.f3("Registering channels...");
initChannels(eventBus);
initBus(eventBus);
/*
* Display
@ -98,7 +103,7 @@ public abstract class BaseApp implements AppAccess {
*/
Log.f2("Initializing Input System...");
inputSystem = new InputSystem(this);
initKeystrokes(inputSystem);
initInputSystem(inputSystem);
/*
* Prepare main loop
@ -130,40 +135,87 @@ public abstract class BaseApp implements AppAccess {
}
/**
* Called at the beginning of the initialization sequence, right after lock
* was obtained.
*/
@NoImpl
protected void preInit()
{
}
/**
*
*/
@NoImpl
protected void postInit()
{
}
/**
* Create and configure a log (using {@link Log})
*
* @return new log instance
*/
protected abstract LogInstance createLog();
/**
* Create window and configure display system
*
* @param display
*/
protected abstract void initDisplay(DisplaySystem display);
/**
* Configure sound system (ie. adjust volume)
*
* @param audio
*/
protected abstract void initSoundSystem(SoundSystem audio);
protected abstract void initKeystrokes(InputSystem input);
/**
* Configure input system (ie. define global keystrokes)
*
* @param input
*/
protected abstract void initInputSystem(InputSystem input);
/**
* Initialize resource banks; {@link AsyncResourceLoader} is already
* started.
*/
protected abstract void initResources();
/**
* Register game screens to the registry.
*
* @param screens
*/
protected abstract void initScreens(ScreenRegistry screens);
/**
* Create game loop instance
*
* @return the game loop.
*/
protected abstract GameLoop createLoop();
protected void initChannels(EventBus bus)
/**
* Initialize event bus (ie. add custom channels)<br>
* When overriding, must call super!
*
* @param bus
*/
protected void initBus(EventBus bus)
{
// framework events
bus.addChannel(DestroyEvent.class, Destroyable.class);
@ -182,7 +234,7 @@ public abstract class BaseApp implements AppAccess {
}
/**
/*
* Try to obtain lock.
*/
private void initLock()

@ -45,6 +45,9 @@ public abstract class GameLoop extends AppModule implements MainLoopTaskRequest.
}
/**
* Start the loop
*/
public void start()
{
timer = new TimerDelta();
@ -70,6 +73,9 @@ public abstract class GameLoop extends AppModule implements MainLoopTaskRequest.
}
/**
* Called before render
*/
@NoImpl
protected void beforeRender()
{
@ -77,6 +83,9 @@ public abstract class GameLoop extends AppModule implements MainLoopTaskRequest.
}
/**
* Called after render
*/
@NoImpl
protected void afterRender()
{

@ -16,6 +16,9 @@ public class SlickLogRedirector implements LogSystem {
LogInstance l;
/**
* @param log log to redirect into
*/
public SlickLogRedirector(LogInstance log) {
this.l = log;
}

@ -21,21 +21,40 @@ public class BufferedHashSet<E> extends HashSet<E> {
private boolean buffering = false;
/**
* make empty
*/
public BufferedHashSet() {
super();
}
/**
* make from elements of a collection
*
* @param c
*/
public BufferedHashSet(Collection<? extends E> c) {
super(c);
}
/**
* make new
*
* @param initialCapacity
* @param loadFactor
*/
public BufferedHashSet(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
}
/**
* make new
*
* @param initialCapacity
*/
public BufferedHashSet(int initialCapacity) {
super(initialCapacity);
}

@ -36,6 +36,7 @@ final public class EventBus implements Destroyable {
/** Whether the bus was destroyed */
private boolean dead = false;
/** Log detailed messages (debug) */
public boolean detailedLogging = false;
@ -255,6 +256,12 @@ final public class EventBus implements Destroyable {
}
/**
* Check if client can be accepted by any channel
*
* @param client tested client
* @return would be accepted
*/
public boolean isClientValid(Object client)
{
assertLive();

@ -24,6 +24,9 @@ public abstract class BusNode implements BusAccess, DelegatingClient, Toggleable
private boolean delegating = true;
/**
* @param busAccess access to bus
*/
public BusNode(BusAccess busAccess) {
this.busAccess = busAccess;
}

@ -12,6 +12,9 @@ import mightypork.gamecore.control.interf.Destroyable;
*/
public abstract class RootBusNode extends BusNode implements Destroyable {
/**
* @param busAccess access to bus
*/
public RootBusNode(BusAccess busAccess) {
super(busAccess);

@ -16,6 +16,11 @@ public class KeyEvent implements Event<KeyEvent.Listener> {
private final char c;
/**
* @param key key that triggered the event. Can be KEY_NONE.
* @param c typed char (can be zero char)
* @param down true = pressed, false = released.
*/
public KeyEvent(int key, char c, boolean down) {
this.key = key;
this.c = c;
@ -65,6 +70,11 @@ public class KeyEvent implements Event<KeyEvent.Listener> {
keh.receive(this);
}
/**
* {@link KeyEvent} listener
*
* @author MightyPork
*/
public interface Listener {
/**

@ -15,6 +15,9 @@ public class MainLoopTaskRequest implements Event<MainLoopTaskRequest.Listener>
private final Runnable task;
/**
* @param task task to run on main thread in rendering context
*/
public MainLoopTaskRequest(Runnable task) {
this.task = task;
}
@ -26,6 +29,11 @@ public class MainLoopTaskRequest implements Event<MainLoopTaskRequest.Listener>
handler.queueTask(task);
}
/**
* {@link MainLoopTaskRequest} listener
*
* @author MightyPork
*/
public interface Listener {
/**

@ -119,6 +119,11 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
handler.receive(this);
}
/**
* {@link MouseButtonEvent} listener
*
* @author MightyPork
*/
public interface Listener {
/**

@ -17,6 +17,10 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
private final Coord pos;
/**
* @param pos end pos
* @param move move vector
*/
public MouseMotionEvent(Coord pos, Coord move) {
this.move = move;
this.pos = pos;
@ -47,6 +51,11 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
keh.receive(this);
}
/**
* {@link MouseMotionEvent} listener
*
* @author MightyPork
*/
public interface Listener {
/**

@ -6,7 +6,7 @@ import mightypork.gamecore.loading.DeferredResource;
/**
* Request to schedule loading a deferred resource.
* Request to load a deferred resource.
*
* @author MightyPork
*/
@ -16,6 +16,9 @@ public class ResourceLoadRequest implements Event<ResourceLoadRequest.Listener>
private final DeferredResource resource;
/**
* @param resource resource to load
*/
public ResourceLoadRequest(DeferredResource resource) {
this.resource = resource;
}
@ -27,6 +30,11 @@ public class ResourceLoadRequest implements Event<ResourceLoadRequest.Listener>
handler.loadResource(resource);
}
/**
* {@link ResourceLoadRequest} listener
*
* @author MightyPork
*/
public interface Listener {
/**

@ -16,6 +16,11 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
private final boolean fsChanged;
/**
* @param fsChanged fullscreen change triggered the event
* @param fullscreen is now fullscreen
* @param size new screen size
*/
public ScreenChangeEvent(boolean fsChanged, boolean fullscreen, Coord size) {
this.fullscreen = fullscreen;
this.screenSize = size;
@ -23,18 +28,27 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
}
/**
* @return true if screen is now fullscreen
*/
public boolean isFullscreen()
{
return fullscreen;
}
/**
* @return true if event was triggered by fullscreen toggle
*/
public boolean fullscreenChanged()
{
return fsChanged;
}
/**
* @return new screen size
*/
public Coord getScreenSize()
{
return screenSize;
@ -47,8 +61,18 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
handler.receive(this);
}
/**
* {@link ScreenChangeEvent} listener
*
* @author MightyPork
*/
public interface Listener {
/**
* Handle event
*
* @param event
*/
void receive(ScreenChangeEvent event);
}
}

@ -15,6 +15,9 @@ public class ScreenRequestEvent implements Event<ScreenRequestEvent.Listener> {
private final String scrName;
/**
* @param screenKey screen name
*/
public ScreenRequestEvent(String screenKey) {
scrName = screenKey;
}
@ -26,8 +29,16 @@ public class ScreenRequestEvent implements Event<ScreenRequestEvent.Listener> {
handler.showScreen(scrName);
}
/**
* {@link ScreenRequestEvent} listener
*
* @author MightyPork
*/
public interface Listener {
/**
* @param key screen to show
*/
void showScreen(String key);
}

@ -8,6 +8,12 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicates that the marked method is not implemented and can be safely
* overriden.
*
* @author MightyPork
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(value = { ElementType.METHOD })

@ -1,6 +1,11 @@
package mightypork.gamecore.control.timing;
/**
* Can be paused & resumed
*
* @author MightyPork
*/
public interface Pauseable {
/**

@ -8,5 +8,10 @@ package mightypork.gamecore.gui;
*/
public interface ActionTrigger {
/**
* Assign an action
*
* @param action action
*/
void setAction(Action action);
}

@ -6,18 +6,35 @@ import mightypork.gamecore.control.AppAccess;
import mightypork.utils.math.constraints.RectConstraint;
/**
* Holder with evenly spaced columns
*
* @author MightyPork
*/
public class ColumnHolder extends ElementHolder {
private final int cols;
private int col = 0;
/**
* @param app app access
* @param context context
* @param rows number of rows
*/
public ColumnHolder(AppAccess app, RectConstraint context, int rows) {
super(app, context);
this.cols = rows;
}
/**
* make a new holder.<br>
* Context must be assigned before rendering.
*
* @param app app access
* @param rows number of rows
*/
public ColumnHolder(AppAccess app, int rows) {
super(app);
this.cols = rows;

@ -22,11 +22,18 @@ public abstract class ElementHolder extends BusNode implements PluggableRenderab
private RectConstraint context;
/**
* @param app app access
*/
public ElementHolder(AppAccess app) {
super(app);
}
/**
* @param app app access
* @param context boudning context
*/
public ElementHolder(AppAccess app, RectConstraint context) {
super(app);
setContext(context);

@ -5,16 +5,27 @@ import mightypork.gamecore.render.Render;
import mightypork.gamecore.render.textures.TxQuad;
/**
* Draws image in given rect
*
* @author MightyPork
*/
public class ImagePainter extends PluggableRenderer {
private TxQuad texture;
/**
* @param texture drawn image
*/
public ImagePainter(TxQuad texture) {
this.texture = texture;
}
/**
* @param texture texture to use
*/
public void setTexture(TxQuad texture)
{
this.texture = texture;

@ -6,6 +6,11 @@ import mightypork.utils.math.constraints.RectConstraint;
import mightypork.utils.math.coord.Rect;
/**
* Renderable that can be assigned different context
*
* @author MightyPork
*/
public interface PluggableRenderable extends Renderable, PluggableContext {
@Override

@ -6,18 +6,35 @@ import mightypork.gamecore.control.AppAccess;
import mightypork.utils.math.constraints.RectConstraint;
/**
* Holder with evenly spaced rows
*
* @author MightyPork
*/
public class RowHolder extends ElementHolder {
private final int rows;
private int row = 0;
/**
* @param app app access
* @param context bounding context
* @param rows number of rows
*/
public RowHolder(AppAccess app, RectConstraint context, int rows) {
super(app, context);
this.rows = rows;
}
/**
* Make a row holder.<br>
* Context must be assigned before rendering.
*
* @param app app access
* @param rows number of rows
*/
public RowHolder(AppAccess app, int rows) {
super(app);
this.rows = rows;

@ -9,6 +9,11 @@ import mightypork.utils.string.StringProvider;
import mightypork.utils.string.StringProvider.StringWrapper;
/**
* Text painting component
*
* @author MightyPork
*/
public class TextPainter extends PluggableRenderer {
private final FontRenderer font;
@ -17,16 +22,35 @@ public class TextPainter extends PluggableRenderer {
private StringProvider text;
/**
* @param font font to use
*/
public TextPainter(GLFont font) {
this(font, Align.LEFT, RGB.WHITE);
}
/**
* Constructor for fixed text
*
* @param font font to use
* @param align text align
* @param color default color
* @param text drawn text
*/
public TextPainter(GLFont font, Align align, RGB color, String text) {
this(font, align, color, new StringWrapper(text));
}
/**
* COnstructor for changeable text.
*
* @param font font to use
* @param align text align
* @param color default color
* @param text text provider
*/
public TextPainter(GLFont font, Align align, RGB color, StringProvider text) {
this.font = new FontRenderer(font);
this.color = color;
@ -35,6 +59,11 @@ public class TextPainter extends PluggableRenderer {
}
/**
* @param font font to use
* @param align text align
* @param color default color
*/
public TextPainter(GLFont font, Align align, RGB color) {
this(font, align, color, (StringProvider) null);
}
@ -63,43 +92,85 @@ public class TextPainter extends PluggableRenderer {
}
/**
* Assign paint color
*
* @param color paint color
*/
public void setColor(RGB color)
{
this.color = color;
}
/**
* Set text align
*
* @param align text align
*/
public void setAlign(Align align)
{
this.align = align;
}
/**
* Set drawn text
*
* @param text text
*/
public void setText(String text)
{
this.text = new StringWrapper(text);
}
/**
* Set drawn text provider
*
* @param text text provider
*/
public void setText(StringProvider text)
{
this.text = text;
}
protected RGB getColor()
/**
* Get draw color.<br>
* <i>This getter is used for getting drawing color; so if it's overriden,
* the draw color can be adjusted in real time.</i>
*
* @return drawing color
*/
public RGB getColor()
{
return color;
}
protected Align getAlign()
/**
* Get text align.<br>
* <i>This getter is used for getting align; so if it's overidden, the align
* can be adjusted in real time.</i>
*
* @return text align
*/
public Align getAlign()
{
return align;
}
protected String getText()
/**
* Get text to draw.<br>
* <i>This getter is used for getting text to draw; so if it's overidden,
* the text can be adjusted in real time. (alternative to using
* StringProvider)</i>
*
* @return text align
*/
public String getText()
{
return text.getString();
}

@ -8,11 +8,19 @@ import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.render.Render;
/**
* Screen with multiple instances of {@link ScreenLayer}
*
* @author MightyPork
*/
public abstract class LayeredScreen extends Screen {
private final Collection<ScreenLayer> layers = new TreeSet<>();
/**
* @param app app access
*/
public LayeredScreen(AppAccess app) {
super(app);
}

@ -28,6 +28,9 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
private volatile boolean needSetupViewport = false;
/**
* @param app app access
*/
public Screen(AppAccess app) {
super(app);

@ -22,6 +22,9 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
private final KeyBindingPool keybindings = new KeyBindingPool();
/**
* @param screen parent screen
*/
public ScreenLayer(Screen screen) {
super(screen); // screen as AppAccess
@ -44,6 +47,9 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
}
/**
* @return parent screen instance
*/
protected final Screen getScreen()
{
return screen;

@ -22,6 +22,9 @@ public class ScreenRegistry extends AppModule implements ScreenRequestEvent.List
private volatile Screen active = null;
/**
* @param app app access
*/
public ScreenRegistry(AppAccess app) {
super(app);
}

@ -19,6 +19,11 @@ import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
/**
* Input system
*
* @author MightyPork
*/
public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
// listeners
@ -27,6 +32,9 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
private static boolean inited = false;
/**
* @param app app access
*/
public InputSystem(AppAccess app) {
super(app);

@ -1,13 +1,21 @@
package mightypork.gamecore.input;
import mightypork.gamecore.gui.Action;
/**
* Can bind events to keys.
*
* @author MightyPork
*/
public interface KeyBinder {
/**
* Bind handler to a keystroke, replace current handler if any
*
* @param stroke trigger keystroke
* @param task handler
* @param task handler; can be {@link Runnable} or {@link Action}
*/
void bindKeyStroke(KeyStroke stroke, Runnable task);

@ -19,9 +19,14 @@ import mightypork.utils.logging.Log;
*/
public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.Listener, Destroyable {
/**
* Start a new loader thread.
*
* @param app app access
*/
public static void launch(BusAccess app)
{
Thread loader = new AsyncResourceLoader(app);
final Thread loader = new AsyncResourceLoader(app);
loader.setDaemon(true);
loader.start();
}
@ -33,6 +38,9 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
private final BusAccess app;
/**
* @param app app acceess
*/
public AsyncResourceLoader(BusAccess app) {
super("Deferred loader");
this.app = app;

@ -21,6 +21,10 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
private volatile boolean loadAttempted = false;
/**
* @param resource resource path / name; this string is later used in
* loadResource()
*/
public BaseDeferredResource(String resource) {
this.resource = resource;
}

@ -7,8 +7,6 @@ import java.nio.ByteBuffer;
import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.AppModule;
import mightypork.gamecore.control.bus.clients.RootBusNode;
import mightypork.gamecore.control.bus.events.DestroyEvent;
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
import mightypork.gamecore.control.timing.FpsMeter;
import mightypork.utils.logging.Log;
@ -23,14 +21,23 @@ import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
/**
* Display system
*
* @author MightyPork
*/
public class DisplaySystem extends AppModule implements RectConstraint {
private DisplayMode windowDisplayMode;
private int targetFps;
/** Y axis goes down (not up); Used also to adjust inputs. */
public static boolean yAxisDown = true;
private FpsMeter fpsMeter;
/**
* @param app app access
*/
public DisplaySystem(AppAccess app) {
super(app);
}
@ -43,12 +50,27 @@ public class DisplaySystem extends AppModule implements RectConstraint {
}
/**
* 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 {
@ -158,12 +180,18 @@ public class DisplaySystem extends AppModule implements RectConstraint {
}
/**
* @return screen width
*/
public static int getWidth()
{
return Display.getWidth();
}
/**
* @return screen height
*/
public static int getHeight()
{
return Display.getHeight();
@ -211,6 +239,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
return fpsMeter.getFPS();
}
/** Screen width constraint */
public static final NumberConstraint width = new NumberConstraint() {
@Override
@ -220,6 +249,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
}
};
/** Screen height constaint */
public static final NumberConstraint height = new NumberConstraint() {
@Override

@ -353,6 +353,13 @@ public class Render {
}
/**
* Draw quad with horizontal gradient
*
* @param quad drawn quad bounds
* @param colorLeft left color
* @param colorRight right color
*/
public static void quadGradH(Rect quad, RGB colorLeft, RGB colorRight)
{
final double left = quad.x1();
@ -377,6 +384,13 @@ public class Render {
}
/**
* Draw quad with vertical gradient
*
* @param quad drawn quad bounds
* @param colorTop top color
* @param colorBottom bottom color
*/
public static void quadGradV(Rect quad, RGB colorTop, RGB colorBottom)
{
final double left = quad.x1();

@ -24,6 +24,12 @@ public class Screenshot {
private BufferedImage image;
/**
* @param width image width
* @param height image height
* @param bpp bits per pixel (typically 4)
* @param buffer
*/
public Screenshot(int width, int height, int bpp, ByteBuffer buffer) {
this.width = width;
this.height = height;
@ -32,6 +38,12 @@ public class Screenshot {
}
/**
* Extract to an image.<br>
* Subsequent calls will use a cached value.
*
* @return image
*/
public BufferedImage getImage()
{
if (image != null) return image;
@ -53,6 +65,13 @@ public class Screenshot {
}
/**
* Save to a file.<br>
* Cached value is used if any.
*
* @param file target file
* @throws IOException on error writing to file
*/
public void save(File file) throws IOException
{
ImageIO.write(getImage(), "PNG", file);

@ -21,6 +21,9 @@ public class FontBank extends AppAdapter {
private static final GLFont NULL_FONT = new NullFont();
/**
* @param app app access
*/
public FontBank(AppAccess app) {
super(app);
}

@ -5,6 +5,11 @@ import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.Coord;
/**
* Interface bor drawable font.
*
* @author MightyPork
*/
public interface GLFont {
/**

@ -41,6 +41,11 @@ public class SlickFont implements GLFont {
}
/**
* Set used filtering
*
* @param filter font filtering mode
*/
public void setFiltering(FilterMode filter)
{
this.filter = filter;

@ -26,11 +26,20 @@ public class DeferredTexture extends BaseDeferredResource implements FilteredTex
private WrapMode wrap = WrapMode.CLAMP;
/**
* @param resourcePath resource path
*/
public DeferredTexture(String resourcePath) {
super(resourcePath);
}
/**
* Get a quad from this texture of given position/size
*
* @param rect quad rect
* @return the quad
*/
public TxQuad getQuad(Rect rect)
{
return new TxQuad(this, rect);
@ -53,6 +62,9 @@ public class DeferredTexture extends BaseDeferredResource implements FilteredTex
}
/**
* Bind without adjusting parameters
*/
public void bindRaw()
{
if (!ensureLoaded()) return;
@ -61,12 +73,15 @@ public class DeferredTexture extends BaseDeferredResource implements FilteredTex
}
/**
* Bind and adjust parameters (filter, wrap)
*/
@Override
public void bind()
{
if (!ensureLoaded()) return;
backingTexture.bind();
bindRaw();
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);

@ -4,6 +4,11 @@ package mightypork.gamecore.render.textures;
import org.lwjgl.opengl.GL11;
/**
* Texture filtering mode
*
* @author MightyPork
*/
public enum FilterMode
{
LINEAR(GL11.GL_LINEAR), NEAREST(GL11.GL_NEAREST);

@ -4,6 +4,11 @@ package mightypork.gamecore.render.textures;
import org.newdawn.slick.opengl.Texture;
/**
* Texture with filter and wrap mode
*
* @author MightyPork
*/
public interface FilteredTexture extends Texture {
/**

@ -18,6 +18,9 @@ import org.newdawn.slick.opengl.Texture;
*/
public class TextureBank extends AppAdapter {
/**
* @param app app access
*/
public TextureBank(AppAccess app) {
super(app);
}

@ -78,12 +78,22 @@ public class TxQuad {
}
/**
* Clone another
*
* @param txQuad a copied quad
*/
public TxQuad(TxQuad txQuad) {
this.tx = txQuad.tx;
this.uvs = txQuad.uvs.copy();
}
/**
* Get copy
*
* @return copy of this
*/
public TxQuad copy()
{
return new TxQuad(this);

@ -4,6 +4,11 @@ package mightypork.gamecore.render.textures;
import org.lwjgl.opengl.GL11;
/**
* Texture wrap mode
*
* @author MightyPork
*/
public enum WrapMode
{
CLAMP(GL11.GL_CLAMP), REPEAT(GL11.GL_REPEAT);

@ -110,7 +110,7 @@ public class App extends BaseApp {
@Override
protected void initKeystrokes(InputSystem input)
protected void initInputSystem(InputSystem input)
{
// Go fullscreen
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() {
@ -177,9 +177,9 @@ public class App extends BaseApp {
@Override
protected void initChannels(EventBus bus)
protected void initBus(EventBus bus)
{
super.initChannels(bus);
super.initBus(bus);
// custom channels
bus.addChannel(ActionRequest.class, ActionRequest.Listener.class);

@ -206,6 +206,13 @@ public class AnimDouble implements Updateable, Pauseable, NumberConstraint {
}
/**
* Get progress already elapsed based on current value.<br>
* Used to resume animation from current point in fading etc.
*
* @param value current value
* @return progress ratio 0-1
*/
protected double getProgressFromValue(double value)
{
double p = 0;

@ -4,7 +4,12 @@ package mightypork.utils.math.constraints;
import mightypork.utils.math.coord.Rect;
public class ContextAdapter implements PluggableContext {
/**
* Basic pluggable context implementation
*
* @author MightyPork
*/
public abstract class ContextAdapter implements PluggableContext {
private RectConstraint backing = null;

@ -1,8 +1,16 @@
package mightypork.utils.math.constraints;
/**
* Numeric constraint
*
* @author MightyPork
*/
public interface NumberConstraint {
/**
* @return current value
*/
double getValue();
}

@ -4,8 +4,16 @@ package mightypork.utils.math.constraints;
import mightypork.utils.math.coord.Rect;
/**
* Interface for constraints that can be assigned context
*
* @author MightyPork
*/
public interface PluggableContext extends RectConstraint {
/**
* @param rect context to set
*/
abstract void setContext(RectConstraint rect);

Loading…
Cancel
Save