Added some informative annotations

v5stable
Ondřej Hruška 11 years ago
parent cacaa9dcce
commit 91f54133b3
  1. 4
      src/mightypork/gamecore/audio/DeferredAudio.java
  2. 4
      src/mightypork/gamecore/audio/NullAudio.java
  3. 2
      src/mightypork/gamecore/control/BaseApp.java
  4. 2
      src/mightypork/gamecore/control/GameLoop.java
  5. 4
      src/mightypork/gamecore/control/bus/EventBus.java
  6. 4
      src/mightypork/gamecore/control/bus/events/Event.java
  7. 3
      src/mightypork/gamecore/control/bus/events/UpdateEvent.java
  8. 3
      src/mightypork/gamecore/gui/components/painters/QuadPainter.java
  9. 2
      src/mightypork/gamecore/gui/screens/Screen.java
  10. 2
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  11. 2
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  12. 8
      src/mightypork/gamecore/loading/AsyncResourceLoader.java
  13. 4
      src/mightypork/gamecore/loading/DeferredResource.java
  14. 4
      src/mightypork/gamecore/render/fonts/impl/DeferredFont.java
  15. 4
      src/mightypork/gamecore/render/fonts/impl/DeferredFontNative.java
  16. 4
      src/mightypork/gamecore/render/textures/DeferredTexture.java
  17. 6
      src/mightypork/utils/annotations/Alias.java
  18. 2
      src/mightypork/utils/annotations/DefaultImpl.java
  19. 19
      src/mightypork/utils/annotations/FactoryMethod.java
  20. 6
      src/mightypork/utils/logging/Log.java
  21. 4
      src/mightypork/utils/math/Calc.java
  22. 2
      src/mightypork/utils/math/Range.java
  23. 5
      src/mightypork/utils/math/animation/Easing.java
  24. 5
      src/mightypork/utils/math/color/RGB.java
  25. 3
      src/mightypork/utils/math/rect/AbstractRect.java
  26. 8
      src/mightypork/utils/math/rect/RectMutable.java
  27. 32
      src/mightypork/utils/math/rect/RectVal.java
  28. 12
      src/mightypork/utils/math/rect/RectView.java
  29. 3
      src/mightypork/utils/math/vect/AbstractVect.java
  30. 4
      src/mightypork/utils/math/vect/Vect.java
  31. 4
      src/mightypork/utils/math/vect/VectAnimated.java
  32. 106
      src/mightypork/utils/math/vect/VectFilters.java
  33. 7
      src/mightypork/utils/math/vect/VectMutable.java
  34. 7
      src/mightypork/utils/math/vect/VectVal.java
  35. 9
      src/mightypork/utils/math/vect/VectView.java
  36. 12
      src/mightypork/utils/objects/Convert.java

@ -4,8 +4,8 @@ package mightypork.gamecore.audio;
import java.io.IOException; import java.io.IOException;
import mightypork.gamecore.loading.DeferredResource; import mightypork.gamecore.loading.DeferredResource;
import mightypork.utils.annotations.Alias;
import mightypork.utils.files.FileUtils; import mightypork.utils.files.FileUtils;
import mightypork.utils.logging.LoggedName;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import org.newdawn.slick.openal.Audio; import org.newdawn.slick.openal.Audio;
@ -17,7 +17,7 @@ import org.newdawn.slick.openal.SoundStore;
* *
* @author MightyPork * @author MightyPork
*/ */
@LoggedName(name = "Audio") @Alias(name = "Audio")
public class DeferredAudio extends DeferredResource { public class DeferredAudio extends DeferredResource {
private enum PlayMode private enum PlayMode

@ -2,7 +2,7 @@ package mightypork.gamecore.audio;
import mightypork.gamecore.loading.NullResource; import mightypork.gamecore.loading.NullResource;
import mightypork.utils.logging.LoggedName; import mightypork.utils.annotations.Alias;
/** /**
@ -11,7 +11,7 @@ import mightypork.utils.logging.LoggedName;
* *
* @author MightyPork * @author MightyPork
*/ */
@LoggedName(name = "NullAudio") @Alias(name = "NullAudio")
public class NullAudio extends DeferredAudio implements NullResource { public class NullAudio extends DeferredAudio implements NullResource {
/** /**

@ -10,13 +10,13 @@ import javax.swing.JOptionPane;
import mightypork.gamecore.audio.SoundSystem; import mightypork.gamecore.audio.SoundSystem;
import mightypork.gamecore.control.bus.EventBus; import mightypork.gamecore.control.bus.EventBus;
import mightypork.gamecore.control.bus.events.*; import mightypork.gamecore.control.bus.events.*;
import mightypork.gamecore.control.interf.DefaultImpl;
import mightypork.gamecore.control.interf.Destroyable; import mightypork.gamecore.control.interf.Destroyable;
import mightypork.gamecore.control.timing.Updateable; import mightypork.gamecore.control.timing.Updateable;
import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.loading.AsyncResourceLoader; import mightypork.gamecore.loading.AsyncResourceLoader;
import mightypork.gamecore.render.DisplaySystem; import mightypork.gamecore.render.DisplaySystem;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.files.InstanceLock; import mightypork.utils.files.InstanceLock;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
import mightypork.utils.logging.LogWriter; import mightypork.utils.logging.LogWriter;

@ -6,10 +6,10 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import mightypork.gamecore.control.bus.events.MainLoopTaskRequest; import mightypork.gamecore.control.bus.events.MainLoopTaskRequest;
import mightypork.gamecore.control.bus.events.UpdateEvent; import mightypork.gamecore.control.bus.events.UpdateEvent;
import mightypork.gamecore.control.interf.DefaultImpl;
import mightypork.gamecore.control.timing.TimerDelta; import mightypork.gamecore.control.timing.TimerDelta;
import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.gui.components.Renderable;
import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.utils.annotations.DefaultImpl;
/** /**

@ -11,6 +11,7 @@ import mightypork.gamecore.control.bus.events.types.ImmediateEvent;
import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent; import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent;
import mightypork.gamecore.control.bus.events.types.UnloggedEvent; import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
import mightypork.gamecore.control.interf.Destroyable; import mightypork.gamecore.control.interf.Destroyable;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -85,12 +86,13 @@ final public class EventBus implements Destroyable {
/** /**
* Add a channel for given event and client type. * Make & connect a channel for given event and client type.
* *
* @param eventClass event type * @param eventClass event type
* @param clientClass client type * @param clientClass client type
* @return the created channel instance * @return the created channel instance
*/ */
@FactoryMethod
public <F_EVENT extends Event<F_CLIENT>, F_CLIENT> EventChannel<?, ?> addChannel(Class<F_EVENT> eventClass, Class<F_CLIENT> clientClass) public <F_EVENT extends Event<F_CLIENT>, F_CLIENT> EventChannel<?, ?> addChannel(Class<F_EVENT> eventClass, Class<F_CLIENT> clientClass)
{ {
assertLive(); assertLive();

@ -4,6 +4,7 @@ package mightypork.gamecore.control.bus.events;
import mightypork.gamecore.control.bus.events.types.DelayedEvent; import mightypork.gamecore.control.bus.events.types.DelayedEvent;
import mightypork.gamecore.control.bus.events.types.ImmediateEvent; import mightypork.gamecore.control.bus.events.types.ImmediateEvent;
import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent; import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent;
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
/** /**
@ -13,7 +14,8 @@ import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent;
* <p> * <p>
* Can be annotated as {@link SingleReceiverEvent} to be delivered once only, * Can be annotated as {@link SingleReceiverEvent} to be delivered once only,
* and {@link DelayedEvent} or {@link ImmediateEvent} to specify default sending * and {@link DelayedEvent} or {@link ImmediateEvent} to specify default sending
* mode. * mode. When marked as {@link UnloggedEvent}, it will not appear in detailed
* bus logging (useful for very frequent events, such as UpdateEvent).
* </p> * </p>
* <p> * <p>
* Default sending mode (if not changed by annotations) is <i>queued</i> with * Default sending mode (if not changed by annotations) is <i>queued</i> with

@ -7,11 +7,10 @@ import mightypork.gamecore.control.timing.Updateable;
/** /**
* Delta timing update event * Delta timing update event. Not logged.
* *
* @author MightyPork * @author MightyPork
*/ */
// sending via queue would hog the bus
@UnloggedEvent @UnloggedEvent
@ImmediateEvent @ImmediateEvent
public class UpdateEvent implements Event<Updateable> { public class UpdateEvent implements Event<Updateable> {

@ -3,6 +3,7 @@ package mightypork.gamecore.gui.components.painters;
import mightypork.gamecore.gui.components.PluggableRenderer; import mightypork.gamecore.gui.components.PluggableRenderer;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.color.RGB; import mightypork.utils.math.color.RGB;
@ -55,12 +56,14 @@ public class QuadPainter extends PluggableRenderer {
} }
@FactoryMethod
public static QuadPainter gradH(RGB colorLeft, RGB colorRight) public static QuadPainter gradH(RGB colorLeft, RGB colorRight)
{ {
return new QuadPainter(colorLeft, colorRight, colorRight, colorLeft); return new QuadPainter(colorLeft, colorRight, colorRight, colorLeft);
} }
@FactoryMethod
public static QuadPainter gradV(RGB colorTop, RGB colorBottom) public static QuadPainter gradV(RGB colorTop, RGB colorBottom)
{ {
return new QuadPainter(colorTop, colorTop, colorBottom, colorBottom); return new QuadPainter(colorTop, colorTop, colorBottom, colorBottom);

@ -4,12 +4,12 @@ package mightypork.gamecore.gui.screens;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.AppSubModule; import mightypork.gamecore.control.AppSubModule;
import mightypork.gamecore.control.bus.events.ScreenChangeEvent; import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
import mightypork.gamecore.control.interf.DefaultImpl;
import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.gui.components.Renderable;
import mightypork.gamecore.input.KeyBinder; import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectView; import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;

@ -2,11 +2,11 @@ package mightypork.gamecore.gui.screens;
import mightypork.gamecore.control.AppSubModule; import mightypork.gamecore.control.AppSubModule;
import mightypork.gamecore.control.interf.DefaultImpl;
import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.gui.components.Renderable;
import mightypork.gamecore.input.KeyBinder; import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectView; import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;

@ -6,8 +6,8 @@ import java.util.HashMap;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.AppModule; import mightypork.gamecore.control.AppModule;
import mightypork.gamecore.control.bus.events.ScreenRequestEvent; import mightypork.gamecore.control.bus.events.ScreenRequestEvent;
import mightypork.gamecore.control.interf.DefaultImpl;
import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.gui.components.Renderable;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;

@ -8,6 +8,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import mightypork.gamecore.control.bus.BusAccess; import mightypork.gamecore.control.bus.BusAccess;
import mightypork.gamecore.control.bus.events.ResourceLoadRequest; import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
import mightypork.gamecore.control.interf.Destroyable; import mightypork.gamecore.control.interf.Destroyable;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -22,12 +23,15 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
* Start a new loader thread. * Start a new loader thread.
* *
* @param app app access * @param app app access
* @return the launched thread
*/ */
public static void launch(BusAccess app) @FactoryMethod
public static AsyncResourceLoader launch(BusAccess app)
{ {
final Thread loader = new AsyncResourceLoader(app); final AsyncResourceLoader loader = new AsyncResourceLoader(app);
loader.setDaemon(true); loader.setDaemon(true);
loader.start(); loader.start();
return loader;
} }
private final ExecutorService exs = Executors.newCachedThreadPool(); private final ExecutorService exs = Executors.newCachedThreadPool();

@ -2,8 +2,8 @@ package mightypork.gamecore.loading;
import mightypork.gamecore.control.interf.Destroyable; import mightypork.gamecore.control.interf.Destroyable;
import mightypork.utils.annotations.Alias;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
import mightypork.utils.logging.LoggedName;
/** /**
@ -13,7 +13,7 @@ import mightypork.utils.logging.LoggedName;
* *
* @author MightyPork * @author MightyPork
*/ */
@LoggedName(name = "Resource") @Alias(name = "Resource")
public abstract class DeferredResource implements Deferred, Destroyable { public abstract class DeferredResource implements Deferred, Destroyable {
private final String resource; private final String resource;

@ -10,8 +10,8 @@ import mightypork.gamecore.loading.DeferredResource;
import mightypork.gamecore.loading.MustLoadInMainThread; import mightypork.gamecore.loading.MustLoadInMainThread;
import mightypork.gamecore.render.fonts.GLFont; import mightypork.gamecore.render.fonts.GLFont;
import mightypork.gamecore.render.textures.FilterMode; import mightypork.gamecore.render.textures.FilterMode;
import mightypork.utils.annotations.Alias;
import mightypork.utils.files.FileUtils; import mightypork.utils.files.FileUtils;
import mightypork.utils.logging.LoggedName;
import mightypork.utils.math.color.RGB; import mightypork.utils.math.color.RGB;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView; import mightypork.utils.math.vect.VectView;
@ -23,7 +23,7 @@ import mightypork.utils.math.vect.VectView;
* @author MightyPork * @author MightyPork
*/ */
@MustLoadInMainThread @MustLoadInMainThread
@LoggedName(name = "Font") @Alias(name = "Font")
public class DeferredFont extends DeferredResource implements GLFont { public class DeferredFont extends DeferredResource implements GLFont {
public static enum FontStyle public static enum FontStyle

@ -6,7 +6,7 @@ import java.awt.FontFormatException;
import java.io.IOException; import java.io.IOException;
import mightypork.gamecore.render.textures.FilterMode; import mightypork.gamecore.render.textures.FilterMode;
import mightypork.utils.logging.LoggedName; import mightypork.utils.annotations.Alias;
/** /**
@ -14,7 +14,7 @@ import mightypork.utils.logging.LoggedName;
* *
* @author MightyPork * @author MightyPork
*/ */
@LoggedName(name = "FontNative") @Alias(name = "FontNative")
public class DeferredFontNative extends DeferredFont { public class DeferredFontNative extends DeferredFont {
/** /**

@ -4,7 +4,7 @@ package mightypork.gamecore.render.textures;
import mightypork.gamecore.loading.DeferredResource; import mightypork.gamecore.loading.DeferredResource;
import mightypork.gamecore.loading.MustLoadInMainThread; import mightypork.gamecore.loading.MustLoadInMainThread;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.utils.logging.LoggedName; import mightypork.utils.annotations.Alias;
import mightypork.utils.math.rect.Rect; import mightypork.utils.math.rect.Rect;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -17,7 +17,7 @@ import org.newdawn.slick.opengl.Texture;
* @author MightyPork * @author MightyPork
*/ */
@MustLoadInMainThread @MustLoadInMainThread
@LoggedName(name = "Texture") @Alias(name = "Texture")
public class DeferredTexture extends DeferredResource implements FilteredTexture { public class DeferredTexture extends DeferredResource implements FilteredTexture {
private Texture backingTexture; private Texture backingTexture;

@ -1,4 +1,4 @@
package mightypork.utils.logging; package mightypork.utils.annotations;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
@ -8,14 +8,14 @@ import java.lang.annotation.RetentionPolicy;
/** /**
* Specify pretty name to be used when logging (<code>Log.str()</code>) * Specify pretty name to be used when logging (eg. <code>Log.str()</code>)
* *
* @author MightyPork * @author MightyPork
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Inherited @Inherited
@Documented @Documented
public @interface LoggedName { public @interface Alias {
String name(); String name();
} }

@ -1,4 +1,4 @@
package mightypork.gamecore.control.interf; package mightypork.utils.annotations;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;

@ -0,0 +1,19 @@
package mightypork.utils.annotations;
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;
/**
* Marks a static factory method
*
* @author MightyPork
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
@Documented
public @interface FactoryMethod {
}

@ -7,6 +7,8 @@ import java.io.StringWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.logging.Level; import java.util.logging.Level;
import mightypork.utils.annotations.Alias;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.string.StringUtils; import mightypork.utils.string.StringUtils;
@ -34,6 +36,7 @@ public class Log {
* @param oldLogsCount number of old logs to keep, -1 infinite, 0 none. * @param oldLogsCount number of old logs to keep, -1 infinite, 0 none.
* @return the created Log instance * @return the created Log instance
*/ */
@FactoryMethod
public static synchronized LogWriter create(String logName, File logFile, int oldLogsCount) public static synchronized LogWriter create(String logName, File logFile, int oldLogsCount)
{ {
if (logs.containsKey(logName)) return logs.get(logName); if (logs.containsKey(logName)) return logs.get(logName);
@ -55,6 +58,7 @@ public class Log {
* @param logFile log file; old logs will be kept here too. * @param logFile log file; old logs will be kept here too.
* @return the created Log instance * @return the created Log instance
*/ */
@FactoryMethod
public static synchronized LogWriter create(String logName, File logFile) public static synchronized LogWriter create(String logName, File logFile)
{ {
if (logs.containsKey(logName)) return logs.get(logName); if (logs.containsKey(logName)) return logs.get(logName);
@ -348,7 +352,7 @@ public class Log {
public static String str(Class<?> cls) public static String str(Class<?> cls)
{ {
final LoggedName ln = cls.getAnnotation(LoggedName.class); final Alias ln = cls.getAnnotation(Alias.class);
if (ln != null) { if (ln != null) {
return ln.name(); return ln.name();
} }

@ -682,7 +682,7 @@ public class Calc {
* @param d double * @param d double
* @return string * @return string
*/ */
public static String doubleToString(double d) public static String toString(double d)
{ {
String s = Double.toString(d); String s = Double.toString(d);
s = s.replaceAll("([0-9]+\\.[0-9]+)00+[0-9]+", "$1"); s = s.replaceAll("([0-9]+\\.[0-9]+)00+[0-9]+", "$1");
@ -698,7 +698,7 @@ public class Calc {
* @param f float * @param f float
* @return string * @return string
*/ */
public static String floatToString(float f) public static String toString(float f)
{ {
String s = Float.toString(f); String s = Float.toString(f);
s = s.replaceAll("([0-9]+\\.[0-9]+)00+[0-9]+", "$1"); s = s.replaceAll("([0-9]+\\.[0-9]+)00+[0-9]+", "$1");

@ -137,7 +137,7 @@ public class Range {
@Override @Override
public String toString() public String toString()
{ {
return String.format("Range(%.1f|%.1f)", min, max); return String.format("{%.1f|%.1f}", min, max);
} }

@ -1,5 +1,7 @@
package mightypork.utils.math.animation; package mightypork.utils.math.animation;
import mightypork.utils.annotations.FactoryMethod;
/** /**
* EasingFunction function. * EasingFunction function.
@ -23,6 +25,7 @@ public abstract class Easing {
* @param original original easing * @param original original easing
* @return reversed easing * @return reversed easing
*/ */
@FactoryMethod
public static Easing reverse(Easing original) public static Easing reverse(Easing original)
{ {
return new Reverse(original); return new Reverse(original);
@ -36,6 +39,7 @@ public abstract class Easing {
* @param out terminal easing * @param out terminal easing
* @return product * @return product
*/ */
@FactoryMethod
public static Easing combine(Easing in, Easing out) public static Easing combine(Easing in, Easing out)
{ {
return new Composite(in, out); return new Composite(in, out);
@ -48,6 +52,7 @@ public abstract class Easing {
* @param in initial easing * @param in initial easing
* @return product * @return product
*/ */
@FactoryMethod
public static Easing inOut(Easing in) public static Easing inOut(Easing in)
{ {
return combine(in, reverse(in)); return combine(in, reverse(in));

@ -3,6 +3,7 @@ package mightypork.utils.math.color;
import java.awt.Color; import java.awt.Color;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.Calc; import mightypork.utils.math.Calc;
@ -337,6 +338,7 @@ public class RGB {
* @param hex hex RRGGBB * @param hex hex RRGGBB
* @return the new color * @return the new color
*/ */
@FactoryMethod
public static RGB fromHex(int hex) public static RGB fromHex(int hex)
{ {
final int bi = hex & 0xff; final int bi = hex & 0xff;
@ -352,6 +354,7 @@ public class RGB {
* @param color HSV color * @param color HSV color
* @return RGB * @return RGB
*/ */
@FactoryMethod
public static RGB fromHSV(HSV color) public static RGB fromHSV(HSV color)
{ {
return color.toRGB(); return color.toRGB();
@ -381,12 +384,14 @@ public class RGB {
} }
@FactoryMethod
public static RGB dark(double d) public static RGB dark(double d)
{ {
return new RGB(0, 0, 0, d); return new RGB(0, 0, 0, d);
} }
@FactoryMethod
public static RGB light(double d) public static RGB light(double d)
{ {
return new RGB(1, 1, 1, d); return new RGB(1, 1, 1, d);

@ -144,6 +144,8 @@ public abstract class AbstractRect implements Rect {
@Override @Override
public RectView view() public RectView view()
{ {
// must NOT call VectView.make, it'd cause infinite recursion.
if (proxy == null) proxy = new RectProxy(this); if (proxy == null) proxy = new RectProxy(this);
return proxy; return proxy;
@ -153,6 +155,7 @@ public abstract class AbstractRect implements Rect {
@Override @Override
public RectVal copy() public RectVal copy()
{ {
// must NOT call RectVal.make, it'd cause infinite recursion.
return new RectVal(x(), y(), width(), height()); return new RectVal(x(), y(), width(), height());
} }

@ -1,6 +1,7 @@
package mightypork.utils.math.rect; package mightypork.utils.math.rect;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVal;
@ -17,6 +18,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
* *
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectMutable zero() public static RectMutable zero()
{ {
return make(0, 0, 0, 0); return make(0, 0, 0, 0);
@ -28,6 +30,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
* *
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectMutable one() public static RectMutable one()
{ {
return make(0, 0, 1, 1); return make(0, 0, 1, 1);
@ -55,6 +58,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
* @param height * @param height
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectMutable make(Vect origin, double width, double height) public static RectMutable make(Vect origin, double width, double height)
{ {
return make(origin, VectVal.make(width, height)); return make(origin, VectVal.make(width, height));
@ -67,6 +71,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
* @param size * @param size
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectMutable make(Vect size) public static RectMutable make(Vect size)
{ {
return make(Vect.ZERO, size); return make(Vect.ZERO, size);
@ -82,6 +87,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
* @param height * @param height
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectMutable make(double x, double y, double width, double height) public static RectMutable make(double x, double y, double width, double height)
{ {
return make(x, y, width, height); return make(x, y, width, height);
@ -94,6 +100,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
* @param other copied * @param other copied
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectMutable make(Rect other) public static RectMutable make(Rect other)
{ {
return make(other.origin(), other.size()); return make(other.origin(), other.size());
@ -107,6 +114,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
* @param size * @param size
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectMutable make(Vect origin, Vect size) public static RectMutable make(Vect origin, Vect size)
{ {
return make(origin.x(), origin.y(), size.x(), size.y()); return make(origin.x(), origin.y(), size.x(), size.y());

@ -1,6 +1,7 @@
package mightypork.utils.math.rect; package mightypork.utils.math.rect;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVal;
@ -18,31 +19,10 @@ public class RectVal extends RectView {
* @param observed observed rect * @param observed observed rect
* @return view * @return view
*/ */
@FactoryMethod
public static RectVal make(Rect observed) public static RectVal make(Rect observed)
{ {
return observed.copy(); return observed.copy(); // let the rect handle it
}
/**
* Create at 0,0 with zero size
*
* @return new mutable rect
*/
public static RectVal zero()
{
return make(0, 0, 0, 0);
}
/**
* Create at 1,1 with zero size
*
* @return new mutable rect
*/
public static RectVal one()
{
return make(0, 0, 1, 1);
} }
@ -53,6 +33,7 @@ public class RectVal extends RectView {
* @param height * @param height
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectVal make(double width, double height) public static RectVal make(double width, double height)
{ {
return make(0, 0, width, height); return make(0, 0, width, height);
@ -67,6 +48,7 @@ public class RectVal extends RectView {
* @param height * @param height
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectVal make(Vect origin, double width, double height) public static RectVal make(Vect origin, double width, double height)
{ {
return make(origin, VectVal.make(width, height)); return make(origin, VectVal.make(width, height));
@ -79,6 +61,7 @@ public class RectVal extends RectView {
* @param size * @param size
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectVal make(Vect size) public static RectVal make(Vect size)
{ {
return make(Vect.ZERO, size); return make(Vect.ZERO, size);
@ -94,6 +77,7 @@ public class RectVal extends RectView {
* @param height * @param height
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectVal make(double x, double y, double width, double height) public static RectVal make(double x, double y, double width, double height)
{ {
return new RectVal(x, y, width, height); return new RectVal(x, y, width, height);
@ -107,6 +91,7 @@ public class RectVal extends RectView {
* @param size * @param size
* @return new mutable rect * @return new mutable rect
*/ */
@FactoryMethod
public static RectVal make(Vect origin, Vect size) public static RectVal make(Vect origin, Vect size)
{ {
return make(origin.x(), origin.y(), size.x(), size.y()); return make(origin.x(), origin.y(), size.x(), size.y());
@ -133,6 +118,7 @@ public class RectVal extends RectView {
@Override @Override
public RectVal copy() public RectVal copy()
{ {
// must NOT call RectVal.make, it'd cause infinite recursion.
return this; // nothing can change. return this; // nothing can change.
} }

@ -1,5 +1,7 @@
package mightypork.utils.math.rect; package mightypork.utils.math.rect;
import mightypork.utils.annotations.FactoryMethod;
/** /**
* Immutable rect * Immutable rect
@ -14,9 +16,10 @@ public abstract class RectView extends RectMath<RectVal> {
* @param observed observed rect * @param observed observed rect
* @return view * @return view
*/ */
@FactoryMethod
public static RectView make(Rect observed) public static RectView make(Rect observed)
{ {
return observed.view(); return observed.view(); // let the rect handle it
} }
@ -47,4 +50,11 @@ public abstract class RectView extends RectMath<RectVal> {
return RectVal.make(origin().round(), size().round()); return RectVal.make(origin().round(), size().round());
} }
@Override
public RectView view()
{
// must NOT call RectView.make, it'd cause infinite recursion.
return this; // wont change
}
} }

@ -118,6 +118,7 @@ public abstract class AbstractVect implements Vect {
@Override @Override
public VectVal copy() public VectVal copy()
{ {
// must NOT call VectVal.make, it'd cause infinite recursion.
return new VectVal(this); return new VectVal(this);
} }
@ -125,6 +126,8 @@ public abstract class AbstractVect implements Vect {
@Override @Override
public VectView view() public VectView view()
{ {
// must NOT call VectView.make, it'd cause infinite recursion.
if (proxy == null) proxy = new VectProxy(this); if (proxy == null) proxy = new VectProxy(this);
return proxy; return proxy;

@ -12,8 +12,8 @@ import mightypork.utils.math.constraints.VectBound;
*/ */
public interface Vect extends VectBound { public interface Vect extends VectBound {
public static final VectVal ZERO = new VectVal(0, 0, 0); VectVal ZERO = new VectVal(0, 0, 0);
public static final VectVal ONE = new VectVal(0, 0, 0); VectVal ONE = new VectVal(0, 0, 0);
/** /**

@ -3,6 +3,7 @@ package mightypork.utils.math.vect;
import mightypork.gamecore.control.timing.Pauseable; import mightypork.gamecore.control.timing.Pauseable;
import mightypork.gamecore.control.timing.Updateable; import mightypork.gamecore.control.timing.Updateable;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.animation.AnimDouble; import mightypork.utils.math.animation.AnimDouble;
import mightypork.utils.math.animation.Easing; import mightypork.utils.math.animation.Easing;
@ -23,6 +24,7 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
* @param z z animator * @param z z animator
* @return animated mutable vector * @return animated mutable vector
*/ */
@FactoryMethod
public static VectAnimated make(AnimDouble x, AnimDouble y, AnimDouble z) public static VectAnimated make(AnimDouble x, AnimDouble y, AnimDouble z)
{ {
return new VectAnimated(x, y, z); return new VectAnimated(x, y, z);
@ -36,6 +38,7 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
* @param easing animation easing * @param easing animation easing
* @return animated mutable vector * @return animated mutable vector
*/ */
@FactoryMethod
public static VectAnimated make(Vect start, Easing easing) public static VectAnimated make(Vect start, Easing easing)
{ {
return new VectAnimated(start, easing); return new VectAnimated(start, easing);
@ -48,6 +51,7 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
* @param easing animation easing * @param easing animation easing
* @return animated mutable vector * @return animated mutable vector
*/ */
@FactoryMethod
public static VectAnimated make(Easing easing) public static VectAnimated make(Easing easing)
{ {
return new VectAnimated(Vect.ZERO, easing); return new VectAnimated(Vect.ZERO, easing);

@ -1,106 +0,0 @@
package mightypork.utils.math.vect;
public class VectFilters {
private static abstract class Uniform extends VectProxy {
public Uniform(Vect observed) {
super(observed);
}
@Override
protected double processX(double x)
{
return super.processX(x);
}
@Override
protected double processY(double y)
{
return super.processY(y);
}
@Override
protected double processZ(double z)
{
return super.processZ(z);
}
protected abstract double process(double a);
}
public static class Round extends Uniform {
public Round(Vect observed) {
super(observed);
}
@Override
protected double process(double a)
{
return Math.round(a);
}
}
public static class Ceil extends Uniform {
public Ceil(Vect observed) {
super(observed);
}
@Override
protected double process(double a)
{
return Math.ceil(a);
}
}
public static class Floor extends Uniform {
public Floor(Vect observed) {
super(observed);
}
@Override
protected double process(double a)
{
return Math.floor(a);
}
}
public static class Neg extends Uniform {
public Neg(Vect observed) {
super(observed);
}
@Override
protected double process(double a)
{
return -a;
}
}
public static class Half extends Uniform {
public Half(Vect observed) {
super(observed);
}
@Override
protected double process(double a)
{
return a / 2D;
}
}
}

@ -1,5 +1,7 @@
package mightypork.utils.math.vect; package mightypork.utils.math.vect;
import mightypork.utils.annotations.FactoryMethod;
@ -15,6 +17,7 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
* *
* @return new mutable vector * @return new mutable vector
*/ */
@FactoryMethod
public static VectMutable zero() public static VectMutable zero()
{ {
return make(ZERO); return make(ZERO);
@ -26,6 +29,7 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
* *
* @return one mutable vector * @return one mutable vector
*/ */
@FactoryMethod
public static VectMutable one() public static VectMutable one()
{ {
return make(ONE); return make(ONE);
@ -39,6 +43,7 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
* @param y Y coordinate * @param y Y coordinate
* @return mutable vector * @return mutable vector
*/ */
@FactoryMethod
public static VectMutable make(double x, double y) public static VectMutable make(double x, double y)
{ {
return make(x, y, 0); return make(x, y, 0);
@ -51,6 +56,7 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
* @param copied copied vec * @param copied copied vec
* @return mutable vector * @return mutable vector
*/ */
@FactoryMethod
public static VectMutable make(Vect copied) public static VectMutable make(Vect copied)
{ {
return make(copied.x(), copied.y(), copied.z()); return make(copied.x(), copied.y(), copied.z());
@ -65,6 +71,7 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
* @param z Z coordinate * @param z Z coordinate
* @return mutable vector * @return mutable vector
*/ */
@FactoryMethod
public static VectMutable make(double x, double y, double z) public static VectMutable make(double x, double y, double z)
{ {
return new VectMutableVariable(x, y, z); return new VectMutableVariable(x, y, z);

@ -1,5 +1,7 @@
package mightypork.utils.math.vect; package mightypork.utils.math.vect;
import mightypork.utils.annotations.FactoryMethod;
/** /**
* Coordinate with immutable numeric values.<br> * Coordinate with immutable numeric values.<br>
@ -15,9 +17,10 @@ public final class VectVal extends VectView {
* @param value source vector * @param value source vector
* @return new constant vec * @return new constant vec
*/ */
@FactoryMethod
public static VectVal make(Vect value) public static VectVal make(Vect value)
{ {
return value.copy(); return value.copy(); // let the vect handle it
} }
@ -28,6 +31,7 @@ public final class VectVal extends VectView {
* @param y Y value * @param y Y value
* @return new constant vec * @return new constant vec
*/ */
@FactoryMethod
public static VectVal make(double x, double y) public static VectVal make(double x, double y)
{ {
return make(x, y, 0); return make(x, y, 0);
@ -42,6 +46,7 @@ public final class VectVal extends VectView {
* @param z Z value * @param z Z value
* @return new constant vector * @return new constant vector
*/ */
@FactoryMethod
public static VectVal make(double x, double y, double z) public static VectVal make(double x, double y, double z)
{ {
return new VectVal(x, y, z); return new VectVal(x, y, z);

@ -1,7 +1,8 @@
package mightypork.utils.math.vect; package mightypork.utils.math.vect;
import mightypork.gamecore.control.interf.DefaultImpl; import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.constraints.NumBound; import mightypork.utils.math.constraints.NumBound;
@ -19,9 +20,10 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
* @param observed vector to observe * @param observed vector to observe
* @return view * @return view
*/ */
@FactoryMethod
public static VectView make(Vect observed) public static VectView make(Vect observed)
{ {
return observed.view(); return observed.view(); // let the vect handle it
} }
@ -32,6 +34,7 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
* @param yc Y value * @param yc Y value
* @return view at the values * @return view at the values
*/ */
@FactoryMethod
public static VectView make(NumBound xc, NumBound yc) public static VectView make(NumBound xc, NumBound yc)
{ {
return new NumConstrVect(xc, yc); return new NumConstrVect(xc, yc);
@ -46,6 +49,7 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
* @param zc Z value * @param zc Z value
* @return view at the values * @return view at the values
*/ */
@FactoryMethod
public static VectView make(NumBound xc, NumBound yc, NumBound zc) public static VectView make(NumBound xc, NumBound yc, NumBound zc)
{ {
return new NumConstrVect(xc, yc, zc); return new NumConstrVect(xc, yc, zc);
@ -62,6 +66,7 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
@Override @Override
public VectView view() public VectView view()
{ {
// must NOT call VectView.copy, it'd cause infinite recursion.
return this; // already a view return this; // already a view
} }

@ -2,6 +2,7 @@ package mightypork.utils.objects;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
import mightypork.utils.math.Calc;
import mightypork.utils.math.Range; import mightypork.utils.math.Range;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVal;
@ -98,6 +99,7 @@ public class Convert {
if (s.equals("true")) return true; if (s.equals("true")) return true;
if (s.equals("yes")) return true; if (s.equals("yes")) return true;
if (s.equals("y")) return true; if (s.equals("y")) return true;
if (s.equals("a")) return true;
if (s.equals("enabled")) return true; if (s.equals("enabled")) return true;
if (s.equals("false")) return false; if (s.equals("false")) return false;
@ -122,18 +124,18 @@ public class Convert {
if (o == null) return def; if (o == null) return def;
if (o instanceof String) return ((String) o); if (o instanceof String) return ((String) o);
if (o instanceof Boolean) { if (o instanceof Float) return Calc.toString((float) o);
return (Boolean) o ? "True" : "False";
} if (o instanceof Double) return Calc.toString((double) o);
if (o instanceof Vect) { if (o instanceof Vect) {
final Vect c = (Vect) o; final Vect c = (Vect) o;
return String.format("[%f;%f;%f]", c.x(), c.y(), c.z()); return String.format("(%f|%f|%f)", c.x(), c.y(), c.z());
} }
if (o instanceof Range) { if (o instanceof Range) {
final Range c = (Range) o; final Range c = (Range) o;
return String.format("(%f:%f)", c.getMin(), c.getMax()); return String.format("{%f|%f}", c.getMin(), c.getMax());
} }
if (o instanceof Class<?>) { if (o instanceof Class<?>) {

Loading…
Cancel
Save