Renaming, JavaDoc, fixed bug with layers not resizing when not visible.

v5stable
Ondřej Hruška 10 years ago
parent 6ca6570488
commit 69b0a15be1
  1. 8
      src/mightypork/gamecore/eventbus/EventChannel.java
  2. 21
      src/mightypork/gamecore/eventbus/event_flags/NonRejectableEvent.java
  3. 49
      src/mightypork/gamecore/gui/components/Component.java
  4. 2
      src/mightypork/gamecore/gui/events/LayoutChangeEvent.java
  5. 3
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  6. 8
      src/mightypork/gamecore/resources/AsyncResourceLoader.java
  7. 8
      src/mightypork/gamecore/resources/BaseLazyResource.java
  8. 2
      src/mightypork/gamecore/resources/LazyResource.java
  9. 4
      src/mightypork/gamecore/resources/ResourceLoadRequest.java
  10. 2
      src/mightypork/gamecore/resources/ResourceLoader.java
  11. 2
      src/mightypork/gamecore/resources/TextureBasedResource.java
  12. 6
      src/mightypork/gamecore/resources/audio/LazyAudio.java
  13. 10
      src/mightypork/gamecore/resources/audio/SoundSystem.java
  14. 8
      src/mightypork/gamecore/resources/audio/players/BaseAudioPlayer.java
  15. 4
      src/mightypork/gamecore/resources/audio/players/EffectPlayer.java
  16. 4
      src/mightypork/gamecore/resources/audio/players/LoopPlayer.java
  17. 6
      src/mightypork/gamecore/resources/fonts/FontRegistry.java
  18. 17
      src/mightypork/gamecore/resources/fonts/GLFont.java
  19. 14
      src/mightypork/gamecore/resources/fonts/impl/LazyFont.java
  20. 4
      src/mightypork/gamecore/resources/fonts/impl/LazyFontNative.java
  21. 10
      src/mightypork/gamecore/resources/fonts/impl/TextureBackedFont.java
  22. 12
      src/mightypork/gamecore/resources/textures/LazyTexture.java
  23. 2
      src/mightypork/gamecore/resources/textures/TextureRegistry.java
  24. 5
      src/mightypork/rogue/Launcher.java
  25. 10
      src/mightypork/rogue/RogueResources.java

@ -6,7 +6,9 @@ import java.util.HashSet;
import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.clients.ToggleableClient;
import mightypork.gamecore.eventbus.event_flags.NonRejectableEvent;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.Utils;
/**
@ -78,9 +80,11 @@ class EventChannel<EVENT extends BusEvent<CLIENT>, CLIENT> {
}
processed.add(client);
final boolean must_deliver = Utils.hasAnnotation(event, NonRejectableEvent.class);
// opt-out
if (client instanceof ToggleableClient) {
if (!((ToggleableClient) client).isListening()) continue;
if (!must_deliver && !((ToggleableClient) client).isListening()) continue;
}
sendTo(client, event);
@ -89,7 +93,7 @@ class EventChannel<EVENT extends BusEvent<CLIENT>, CLIENT> {
// pass on to delegated clients
if (client instanceof DelegatingClient) {
if (((DelegatingClient) client).doesDelegate()) {
if (must_deliver || ((DelegatingClient) client).doesDelegate()) {
final Collection<?> children = ((DelegatingClient) client).getChildClients();

@ -0,0 +1,21 @@
package mightypork.gamecore.eventbus.event_flags;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Event that is forcibly delivered to all clients (bypass Toggleable etc)
*
* @author MightyPork
*/
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Target(ElementType.TYPE)
public @interface NonRejectableEvent {
}

@ -27,20 +27,69 @@ public interface Component extends Enableable, Hideable, PluggableRenderable {
void updateLayout();
/**
* @return true if mouse is currently over the component
*/
boolean isMouseOver();
/**
* Set alpha multiplier for this and nested components
*
* @param alpha alpha multiplier (dynamic value)
*/
void setAlpha(Num alpha);
/**
* Set alpha multiplier for this and nested components
*
* @param alpha alpha multiplier (constant value)
*/
void setAlpha(double alpha);
/**
* Indirectly enable / disable, used for nested hierarchies.<br>
* When component is twice indirectly disabled, it needs to be twice
* indirectly enabled to be enabled again.
*
* @param yes
*/
void setIndirectlyEnabled(boolean yes);
/**
* Check if the compionent is not indirectly disabled. May still be directly
* disabled.
*
* @return indirectly enabled
*/
boolean isIndirectlyEnabled();
/**
* Check if the component is directly enabled (set by setEnabled()). May
* still be indirectly disabled.
*
* @return directly enabled
*/
boolean isDirectlyEnabled();
/**
* Set directly enabled (must be both directly and indirectly enabled to be
* enabled completely)
*/
@Override
public void setEnabled(boolean yes);
/**
* Check if the component is both directly and indirectly enabled
*
* @return enabled
*/
@Override
public boolean isEnabled();
}

@ -4,6 +4,7 @@ package mightypork.gamecore.gui.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.DirectEvent;
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
import mightypork.gamecore.eventbus.event_flags.NonRejectableEvent;
/**
@ -14,6 +15,7 @@ import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
*/
@DirectEvent
@NonConsumableEvent
@NonRejectableEvent
public class LayoutChangeEvent extends BusEvent<LayoutChangeListener> {
public LayoutChangeEvent()

@ -83,9 +83,6 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
toShow.setActive(true);
active = toShow;
// update layout for screen
fireLayoutUpdateEvent();
}

@ -20,7 +20,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoader, Destr
private final ExecutorService exs = Executors.newCachedThreadPool();
private final LinkedBlockingQueue<DeferredResource> toLoad = new LinkedBlockingQueue<>();
private final LinkedBlockingQueue<LazyResource> toLoad = new LinkedBlockingQueue<>();
private volatile boolean stopped;
private BusAccess app;
private volatile boolean mainLoopQueuing = true;
@ -49,12 +49,12 @@ public class AsyncResourceLoader extends Thread implements ResourceLoader, Destr
@Override
public void loadResource(final DeferredResource resource)
public void loadResource(final LazyResource resource)
{
if (resource.isLoaded()) return;
// textures & fonts needs to be loaded in main thread
if (resource.getClass().isAnnotationPresent(MustLoadInMainThread.class)) {
if (resource.getClass().isAnnotationPresent(TextureBasedResource.class)) {
if (!mainLoopQueuing) {
Log.f3("<LOADER> Cannot load async: " + Log.str(resource));
@ -86,7 +86,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoader, Destr
while (!stopped) {
try {
final DeferredResource def = toLoad.take();
final LazyResource def = toLoad.take();
if (def == null) continue;
if (!def.isLoaded()) {

@ -14,7 +14,7 @@ import mightypork.gamecore.logging.LogAlias;
* @author MightyPork
*/
@LogAlias(name = "Resource")
public abstract class BaseDeferredResource implements DeferredResource, Destroyable {
public abstract class BaseLazyResource implements LazyResource, Destroyable {
private final String resource;
private volatile boolean loadFailed = false;
@ -25,7 +25,7 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
* @param resource resource path / name; this string is later used in
* loadResource()
*/
public BaseDeferredResource(String resource)
public BaseLazyResource(String resource)
{
this.resource = resource;
}
@ -118,8 +118,8 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
{
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof BaseDeferredResource)) return false;
final BaseDeferredResource other = (BaseDeferredResource) obj;
if (!(obj instanceof BaseLazyResource)) return false;
final BaseLazyResource other = (BaseLazyResource) obj;
if (resource == null) {
if (other.resource != null) return false;
} else if (!resource.equals(other.resource)) return false;

@ -6,7 +6,7 @@ package mightypork.gamecore.resources;
*
* @author MightyPork
*/
public interface DeferredResource {
public interface LazyResource {
/**
* Load the actual resource, if not loaded yet.

@ -13,13 +13,13 @@ import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
@SingleReceiverEvent
public class ResourceLoadRequest extends BusEvent<ResourceLoader> {
private final DeferredResource resource;
private final LazyResource resource;
/**
* @param resource resource to load
*/
public ResourceLoadRequest(DeferredResource resource)
public ResourceLoadRequest(LazyResource resource)
{
this.resource = resource;
}

@ -16,7 +16,7 @@ public interface ResourceLoader {
*
* @param resource
*/
void loadResource(DeferredResource resource);
void loadResource(LazyResource resource);
/**

@ -15,4 +15,4 @@ import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Inherited
@Documented
public @interface MustLoadInMainThread {}
public @interface TextureBasedResource {}

@ -5,7 +5,7 @@ import java.io.IOException;
import java.io.InputStream;
import mightypork.gamecore.logging.LogAlias;
import mightypork.gamecore.resources.BaseDeferredResource;
import mightypork.gamecore.resources.BaseLazyResource;
import mightypork.gamecore.util.files.FileUtils;
import mightypork.gamecore.util.math.constraints.vect.Vect;
@ -19,7 +19,7 @@ import org.newdawn.slick.openal.SoundStore;
* @author MightyPork
*/
@LogAlias(name = "Audio")
public class DeferredAudio extends BaseDeferredResource {
public class LazyAudio extends BaseLazyResource {
private enum PlayMode
{
@ -43,7 +43,7 @@ public class DeferredAudio extends BaseDeferredResource {
*
* @param resourceName resource to load when needed
*/
public DeferredAudio(String resourceName)
public LazyAudio(String resourceName)
{
super(resourceName);
}

@ -72,7 +72,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
private final Volume loopsVolume = new JointVolume(masterVolume);
private final Set<LoopPlayer> loopPlayers = new HashSet<>();
private final Set<DeferredAudio> resources = new HashSet<>();
private final Set<LazyAudio> resources = new HashSet<>();
/**
@ -102,7 +102,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
@Override
public void deinit()
{
for (final DeferredAudio r : resources) {
for (final LazyAudio r : resources) {
r.destroy();
}
@ -154,15 +154,15 @@ public class SoundSystem extends RootBusNode implements Updateable {
/**
* Create {@link DeferredAudio} for a resource
* Create {@link LazyAudio} for a resource
*
* @param res a resource name
* @return the resource
* @throws IllegalArgumentException if resource is already registered
*/
private DeferredAudio getResource(String res)
private LazyAudio getResource(String res)
{
final DeferredAudio a = new DeferredAudio(res);
final LazyAudio a = new LazyAudio(res);
getEventBus().send(new ResourceLoadRequest(a));
if (resources.contains(a)) throw new IllegalArgumentException("Sound resource " + res + " is already registered.");

@ -2,7 +2,7 @@ package mightypork.gamecore.resources.audio.players;
import mightypork.gamecore.eventbus.events.Destroyable;
import mightypork.gamecore.resources.audio.DeferredAudio;
import mightypork.gamecore.resources.audio.LazyAudio;
import mightypork.gamecore.resources.audio.Volume;
@ -14,7 +14,7 @@ import mightypork.gamecore.resources.audio.Volume;
public abstract class BaseAudioPlayer implements Destroyable {
/** the track */
private final DeferredAudio audio;
private final LazyAudio audio;
/** base gain for sfx */
private final double baseGain;
@ -32,7 +32,7 @@ public abstract class BaseAudioPlayer implements Destroyable {
* @param baseGain base gain (volume multiplier)
* @param volume colume control
*/
public BaseAudioPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume)
public BaseAudioPlayer(LazyAudio track, double basePitch, double baseGain, Volume volume)
{
this.audio = track;
@ -55,7 +55,7 @@ public abstract class BaseAudioPlayer implements Destroyable {
/**
* @return audio resource
*/
protected DeferredAudio getAudio()
protected LazyAudio getAudio()
{
return audio;
}

@ -1,7 +1,7 @@
package mightypork.gamecore.resources.audio.players;
import mightypork.gamecore.resources.audio.DeferredAudio;
import mightypork.gamecore.resources.audio.LazyAudio;
import mightypork.gamecore.resources.audio.Volume;
import mightypork.gamecore.util.math.constraints.vect.Vect;
@ -19,7 +19,7 @@ public class EffectPlayer extends BaseAudioPlayer {
* @param baseGain base gain (volume multiplier)
* @param volume volume control
*/
public EffectPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume)
public EffectPlayer(LazyAudio track, double basePitch, double baseGain, Volume volume)
{
super(track, (float) basePitch, (float) baseGain, volume);
}

@ -2,7 +2,7 @@ package mightypork.gamecore.resources.audio.players;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.resources.audio.DeferredAudio;
import mightypork.gamecore.resources.audio.LazyAudio;
import mightypork.gamecore.resources.audio.Volume;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.timing.Pauseable;
@ -40,7 +40,7 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable
* @param baseGain base gain (volume multiplier)
* @param volume volume control
*/
public LoopPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume)
public LoopPlayer(LazyAudio track, double basePitch, double baseGain, Volume volume)
{
super(track, (float) basePitch, (float) baseGain, volume);

@ -6,7 +6,7 @@ import java.util.HashMap;
import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.core.AppAccessAdapter;
import mightypork.gamecore.resources.ResourceLoadRequest;
import mightypork.gamecore.resources.fonts.impl.DeferredFont;
import mightypork.gamecore.resources.fonts.impl.LazyFont;
import org.newdawn.slick.opengl.Texture;
@ -31,12 +31,12 @@ public class FontRegistry extends AppAccessAdapter {
/**
* Load a {@link DeferredFont}
* Load a {@link LazyFont}
*
* @param key font key
* @param font font instance
*/
public void addFont(String key, DeferredFont font)
public void addFont(String key, LazyFont font)
{
getEventBus().send(new ResourceLoadRequest(font));

@ -49,11 +49,28 @@ public interface GLFont {
int getFontSize();
/**
* Set what vertical ratio of the font size is blank and should be cut off
* when rendering
*
* @param top top ratio (0-1)
* @param bottom bottom ratio (0-1)
*/
void setDiscardRatio(double top, double bottom);
/**
* Get top discard ratio (blank unused space)
*
* @return ratio
*/
double getTopDiscardRatio();
/**
* Get bottom discard ratio (blank unused space)
*
* @return ratio
*/
double getBottomDiscardRatio();
}

@ -7,8 +7,8 @@ import java.io.IOException;
import java.io.InputStream;
import mightypork.gamecore.logging.LogAlias;
import mightypork.gamecore.resources.BaseDeferredResource;
import mightypork.gamecore.resources.MustLoadInMainThread;
import mightypork.gamecore.resources.BaseLazyResource;
import mightypork.gamecore.resources.TextureBasedResource;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.resources.textures.FilterMode;
import mightypork.gamecore.util.files.FileUtils;
@ -21,9 +21,9 @@ import mightypork.gamecore.util.math.constraints.vect.Vect;
*
* @author MightyPork
*/
@MustLoadInMainThread
@TextureBasedResource
@LogAlias(name = "Font")
public class DeferredFont extends BaseDeferredResource implements GLFont {
public class LazyFont extends BaseLazyResource implements GLFont {
public static enum FontStyle
{
@ -56,7 +56,7 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
* @param chars chars to load; null to load basic chars only
* @param size size (px)
*/
public DeferredFont(String resourcePath, String chars, double size)
public LazyFont(String resourcePath, String chars, double size)
{
this(resourcePath, chars, size, FontStyle.PLAIN, false, FilterMode.NEAREST);
}
@ -72,7 +72,7 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
* @param antialias use antialiasing for caching texture
* @param filter gl filtering mode
*/
public DeferredFont(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;
@ -118,7 +118,7 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
{
final Font awtFont = getAwtFont(path, (float) size, style.numval);
font = new CachedFont(awtFont, antialias, filter, chars);
font = new TextureBackedFont(awtFont, antialias, filter, chars);
font.setDiscardRatio(discardTop, discardBottom);
}

@ -14,7 +14,7 @@ import mightypork.gamecore.resources.textures.FilterMode;
* @author MightyPork
*/
@LogAlias(name = "FontNative")
public class DeferredFontNative extends DeferredFont {
public class LazyFontNative extends LazyFont {
/**
* A font from OS, found by name
@ -26,7 +26,7 @@ public class DeferredFontNative extends DeferredFont {
* @param antialias use antialiasing when drawn on the cache texture
* @param filter GL filtering mode
*/
public DeferredFontNative(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,8 +20,8 @@ import java.util.Map;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.resources.textures.DeferredTexture;
import mightypork.gamecore.resources.textures.FilterMode;
import mightypork.gamecore.resources.textures.LazyTexture;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.VectConst;
@ -41,7 +41,7 @@ import org.newdawn.slick.opengl.GLUtils;
* @author David Aaron Muhar (bobjob)
* @author MightyPork
*/
public class CachedFont implements GLFont {
public class TextureBackedFont implements GLFont {
private class CharTile {
@ -90,7 +90,7 @@ public class CachedFont implements GLFont {
* @param filter used Gl filter
* @param chars chars to load
*/
public CachedFont(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,7 +104,7 @@ public class CachedFont implements GLFont {
* @param filter used Gl filter
* @param chars chars to load
*/
public CachedFont(java.awt.Font font, boolean antialias, FilterMode filter, char[] chars)
public TextureBackedFont(java.awt.Font font, boolean antialias, FilterMode filter, char[] chars)
{
GLUtils.checkGLContext();
@ -379,7 +379,7 @@ public class CachedFont implements GLFont {
{
GLUtils.checkGLContext();
DeferredTexture.lastBind = null; // needs rebind.
LazyTexture.lastBind = null; // needs rebind.
// PUSH
glPushAttrib(GL_ENABLE_BIT);

@ -3,8 +3,8 @@ package mightypork.gamecore.resources.textures;
import mightypork.gamecore.logging.LogAlias;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.BaseDeferredResource;
import mightypork.gamecore.resources.MustLoadInMainThread;
import mightypork.gamecore.resources.BaseLazyResource;
import mightypork.gamecore.resources.TextureBasedResource;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import org.lwjgl.opengl.GL11;
@ -16,10 +16,10 @@ import org.lwjgl.opengl.GL11;
* @author MightyPork
*/
@LogAlias(name = "Texture")
@MustLoadInMainThread
public class DeferredTexture extends BaseDeferredResource implements GLTexture {
@TextureBasedResource
public class LazyTexture extends BaseLazyResource implements GLTexture {
public static DeferredTexture lastBind = null;
public static LazyTexture lastBind = null;
private org.newdawn.slick.opengl.Texture backingTexture;
private FilterMode filter = FilterMode.NEAREST;
@ -31,7 +31,7 @@ public class DeferredTexture extends BaseDeferredResource implements GLTexture {
/**
* @param resourcePath resource path
*/
public DeferredTexture(String resourcePath)
public LazyTexture(String resourcePath)
{
super(resourcePath);
}

@ -61,7 +61,7 @@ public class TextureRegistry extends AppAccessAdapter {
{
if (key != null) if (textures.containsKey(key)) throw new KeyAlreadyExistsException();
final DeferredTexture texture = new DeferredTexture(resourcePath);
final LazyTexture texture = new LazyTexture(resourcePath);
texture.setFilter(filter);
texture.setWrap(wrap);

@ -2,7 +2,6 @@ package mightypork.rogue;
import java.io.File;
import java.util.Arrays;
import java.util.logging.Level;
import mightypork.gamecore.core.BaseApp;
@ -21,7 +20,7 @@ public class Launcher {
// System.out.println("argv = " + Arrays.toString(args)+"\n");
Level llSyso = Level.FINER;
Level llFile = Level.ALL;
final Level llFile = Level.ALL;
File workdir = null;
@ -77,7 +76,7 @@ public class Launcher {
final BaseApp app = new RogueApp(workdir, true);
app.opt().setLogLevel(llFile, llSyso);
app.start();
}

@ -5,7 +5,7 @@ import mightypork.gamecore.resources.ResourceSetup;
import mightypork.gamecore.resources.audio.SoundRegistry;
import mightypork.gamecore.resources.fonts.FontRegistry;
import mightypork.gamecore.resources.fonts.Glyphs;
import mightypork.gamecore.resources.fonts.impl.DeferredFont;
import mightypork.gamecore.resources.fonts.impl.LazyFont;
import mightypork.gamecore.resources.textures.FilterMode;
import mightypork.gamecore.resources.textures.GLTexture;
import mightypork.gamecore.resources.textures.QuadGrid;
@ -20,15 +20,15 @@ public class RogueResources implements ResourceSetup {
@Override
public void addFonts(FontRegistry fonts)
{
DeferredFont font;
LazyFont font;
//fonts.loadFont("polygon_pixel", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16));
fonts.addFont("press_start", font = new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16));
fonts.addFont("press_start", font = new LazyFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16));
fonts.addFont("battlenet", font = new DeferredFont("/res/font/battlenet.ttf", Glyphs.basic, 16));
fonts.addFont("battlenet", font = new LazyFont("/res/font/battlenet.ttf", Glyphs.basic, 16));
font.setDiscardRatio(3 / 16D, 2 / 16D);
fonts.addFont("tinyutf", font = new DeferredFont("/res/font/TinyUnicode2.ttf", Glyphs.basic, 16));
fonts.addFont("tinyutf", font = new LazyFont("/res/font/TinyUnicode2.ttf", Glyphs.basic, 16));
font.setDiscardRatio(5 / 16D, 3 / 16D);
// aliases

Loading…
Cancel
Save