Added some informative annotations
This commit is contained in:
@@ -4,8 +4,8 @@ package mightypork.gamecore.audio;
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.loading.DeferredResource;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.logging.LoggedName;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
import org.newdawn.slick.openal.Audio;
|
||||
@@ -17,7 +17,7 @@ import org.newdawn.slick.openal.SoundStore;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@LoggedName(name = "Audio")
|
||||
@Alias(name = "Audio")
|
||||
public class DeferredAudio extends DeferredResource {
|
||||
|
||||
private enum PlayMode
|
||||
|
||||
@@ -2,7 +2,7 @@ package mightypork.gamecore.audio;
|
||||
|
||||
|
||||
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
|
||||
*/
|
||||
@LoggedName(name = "NullAudio")
|
||||
@Alias(name = "NullAudio")
|
||||
public class NullAudio extends DeferredAudio implements NullResource {
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,13 +10,13 @@ import javax.swing.JOptionPane;
|
||||
import mightypork.gamecore.audio.SoundSystem;
|
||||
import mightypork.gamecore.control.bus.EventBus;
|
||||
import mightypork.gamecore.control.bus.events.*;
|
||||
import mightypork.gamecore.control.interf.DefaultImpl;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.loading.AsyncResourceLoader;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
import mightypork.utils.files.InstanceLock;
|
||||
import mightypork.utils.logging.Log;
|
||||
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.UpdateEvent;
|
||||
import mightypork.gamecore.control.interf.DefaultImpl;
|
||||
import mightypork.gamecore.control.timing.TimerDelta;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
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.UnloggedEvent;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
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 clientClass client type
|
||||
* @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)
|
||||
{
|
||||
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.ImmediateEvent;
|
||||
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>
|
||||
* Can be annotated as {@link SingleReceiverEvent} to be delivered once only,
|
||||
* 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>
|
||||
* 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
|
||||
*/
|
||||
// sending via queue would hog the bus
|
||||
@UnloggedEvent
|
||||
@ImmediateEvent
|
||||
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.render.Render;
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
|
||||
|
||||
@@ -54,13 +55,15 @@ public class QuadPainter extends PluggableRenderer {
|
||||
Render.quadColor(getRect(), colorHMinVMin, colorHMaxVMin, colorHMaxVMax, colorHMinVMax);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@FactoryMethod
|
||||
public static QuadPainter gradH(RGB colorLeft, RGB colorRight)
|
||||
{
|
||||
return new QuadPainter(colorLeft, colorRight, colorRight, colorLeft);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@FactoryMethod
|
||||
public static QuadPainter gradV(RGB colorTop, RGB 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.AppSubModule;
|
||||
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||
import mightypork.gamecore.control.interf.DefaultImpl;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.gamecore.input.KeyBinder;
|
||||
import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
import mightypork.utils.math.constraints.RectBound;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
@@ -2,11 +2,11 @@ package mightypork.gamecore.gui.screens;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppSubModule;
|
||||
import mightypork.gamecore.control.interf.DefaultImpl;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.gamecore.input.KeyBinder;
|
||||
import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
import mightypork.utils.math.constraints.RectBound;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.HashMap;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppModule;
|
||||
import mightypork.gamecore.control.bus.events.ScreenRequestEvent;
|
||||
import mightypork.gamecore.control.interf.DefaultImpl;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
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.events.ResourceLoadRequest;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
@@ -22,12 +23,15 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
|
||||
* Start a new loader thread.
|
||||
*
|
||||
* @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.start();
|
||||
return loader;
|
||||
}
|
||||
|
||||
private final ExecutorService exs = Executors.newCachedThreadPool();
|
||||
|
||||
@@ -2,8 +2,8 @@ package mightypork.gamecore.loading;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.logging.LoggedName;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ import mightypork.utils.logging.LoggedName;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@LoggedName(name = "Resource")
|
||||
@Alias(name = "Resource")
|
||||
public abstract class DeferredResource implements Deferred, Destroyable {
|
||||
|
||||
private final String resource;
|
||||
|
||||
@@ -10,8 +10,8 @@ import mightypork.gamecore.loading.DeferredResource;
|
||||
import mightypork.gamecore.loading.MustLoadInMainThread;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.gamecore.render.textures.FilterMode;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.logging.LoggedName;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
@@ -23,7 +23,7 @@ import mightypork.utils.math.vect.VectView;
|
||||
* @author MightyPork
|
||||
*/
|
||||
@MustLoadInMainThread
|
||||
@LoggedName(name = "Font")
|
||||
@Alias(name = "Font")
|
||||
public class DeferredFont extends DeferredResource implements GLFont {
|
||||
|
||||
public static enum FontStyle
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.awt.FontFormatException;
|
||||
import java.io.IOException;
|
||||
|
||||
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
|
||||
*/
|
||||
@LoggedName(name = "FontNative")
|
||||
@Alias(name = "FontNative")
|
||||
public class DeferredFontNative extends DeferredFont {
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@ package mightypork.gamecore.render.textures;
|
||||
import mightypork.gamecore.loading.DeferredResource;
|
||||
import mightypork.gamecore.loading.MustLoadInMainThread;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.logging.LoggedName;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.math.rect.Rect;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -17,7 +17,7 @@ import org.newdawn.slick.opengl.Texture;
|
||||
* @author MightyPork
|
||||
*/
|
||||
@MustLoadInMainThread
|
||||
@LoggedName(name = "Texture")
|
||||
@Alias(name = "Texture")
|
||||
public class DeferredTexture extends DeferredResource implements FilteredTexture {
|
||||
|
||||
private Texture backingTexture;
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.logging;
|
||||
package mightypork.utils.annotations;
|
||||
|
||||
|
||||
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
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface LoggedName {
|
||||
public @interface Alias {
|
||||
|
||||
String name();
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.gamecore.control.interf;
|
||||
package mightypork.utils.annotations;
|
||||
|
||||
|
||||
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.logging.Level;
|
||||
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.string.StringUtils;
|
||||
|
||||
|
||||
@@ -34,6 +36,7 @@ public class Log {
|
||||
* @param oldLogsCount number of old logs to keep, -1 infinite, 0 none.
|
||||
* @return the created Log instance
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static synchronized LogWriter create(String logName, File logFile, int oldLogsCount)
|
||||
{
|
||||
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.
|
||||
* @return the created Log instance
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static synchronized LogWriter create(String logName, File logFile)
|
||||
{
|
||||
if (logs.containsKey(logName)) return logs.get(logName);
|
||||
@@ -348,7 +352,7 @@ public class Log {
|
||||
|
||||
public static String str(Class<?> cls)
|
||||
{
|
||||
final LoggedName ln = cls.getAnnotation(LoggedName.class);
|
||||
final Alias ln = cls.getAnnotation(Alias.class);
|
||||
if (ln != null) {
|
||||
return ln.name();
|
||||
}
|
||||
|
||||
@@ -682,7 +682,7 @@ public class Calc {
|
||||
* @param d double
|
||||
* @return string
|
||||
*/
|
||||
public static String doubleToString(double d)
|
||||
public static String toString(double d)
|
||||
{
|
||||
String s = Double.toString(d);
|
||||
s = s.replaceAll("([0-9]+\\.[0-9]+)00+[0-9]+", "$1");
|
||||
@@ -698,7 +698,7 @@ public class Calc {
|
||||
* @param f float
|
||||
* @return string
|
||||
*/
|
||||
public static String floatToString(float f)
|
||||
public static String toString(float f)
|
||||
{
|
||||
String s = Float.toString(f);
|
||||
s = s.replaceAll("([0-9]+\\.[0-9]+)00+[0-9]+", "$1");
|
||||
|
||||
@@ -137,7 +137,7 @@ public class Range {
|
||||
@Override
|
||||
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;
|
||||
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
|
||||
|
||||
/**
|
||||
* EasingFunction function.
|
||||
@@ -23,6 +25,7 @@ public abstract class Easing {
|
||||
* @param original original easing
|
||||
* @return reversed easing
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static Easing reverse(Easing original)
|
||||
{
|
||||
return new Reverse(original);
|
||||
@@ -36,6 +39,7 @@ public abstract class Easing {
|
||||
* @param out terminal easing
|
||||
* @return product
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static Easing combine(Easing in, Easing out)
|
||||
{
|
||||
return new Composite(in, out);
|
||||
@@ -48,6 +52,7 @@ public abstract class Easing {
|
||||
* @param in initial easing
|
||||
* @return product
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static Easing inOut(Easing in)
|
||||
{
|
||||
return combine(in, reverse(in));
|
||||
|
||||
@@ -3,6 +3,7 @@ package mightypork.utils.math.color;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.math.Calc;
|
||||
|
||||
|
||||
@@ -337,6 +338,7 @@ public class RGB {
|
||||
* @param hex hex RRGGBB
|
||||
* @return the new color
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RGB fromHex(int hex)
|
||||
{
|
||||
final int bi = hex & 0xff;
|
||||
@@ -352,6 +354,7 @@ public class RGB {
|
||||
* @param color HSV color
|
||||
* @return RGB
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RGB fromHSV(HSV color)
|
||||
{
|
||||
return color.toRGB();
|
||||
@@ -381,12 +384,14 @@ public class RGB {
|
||||
}
|
||||
|
||||
|
||||
@FactoryMethod
|
||||
public static RGB dark(double d)
|
||||
{
|
||||
return new RGB(0, 0, 0, d);
|
||||
}
|
||||
|
||||
|
||||
@FactoryMethod
|
||||
public static RGB light(double d)
|
||||
{
|
||||
return new RGB(1, 1, 1, d);
|
||||
|
||||
@@ -144,6 +144,8 @@ public abstract class AbstractRect implements Rect {
|
||||
@Override
|
||||
public RectView view()
|
||||
{
|
||||
// must NOT call VectView.make, it'd cause infinite recursion.
|
||||
|
||||
if (proxy == null) proxy = new RectProxy(this);
|
||||
|
||||
return proxy;
|
||||
@@ -153,6 +155,7 @@ public abstract class AbstractRect implements Rect {
|
||||
@Override
|
||||
public RectVal copy()
|
||||
{
|
||||
// must NOT call RectVal.make, it'd cause infinite recursion.
|
||||
return new RectVal(x(), y(), width(), height());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mightypork.utils.math.rect;
|
||||
|
||||
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
|
||||
@@ -17,6 +18,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
*
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectMutable zero()
|
||||
{
|
||||
return make(0, 0, 0, 0);
|
||||
@@ -28,6 +30,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
*
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectMutable one()
|
||||
{
|
||||
return make(0, 0, 1, 1);
|
||||
@@ -55,6 +58,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param height
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectMutable make(Vect origin, double width, double height)
|
||||
{
|
||||
return make(origin, VectVal.make(width, height));
|
||||
@@ -67,6 +71,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param size
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectMutable make(Vect size)
|
||||
{
|
||||
return make(Vect.ZERO, size);
|
||||
@@ -82,6 +87,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param height
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectMutable make(double x, double y, double width, double height)
|
||||
{
|
||||
return make(x, y, width, height);
|
||||
@@ -94,6 +100,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param other copied
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectMutable make(Rect other)
|
||||
{
|
||||
return make(other.origin(), other.size());
|
||||
@@ -107,6 +114,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param size
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectMutable make(Vect origin, Vect size)
|
||||
{
|
||||
return make(origin.x(), origin.y(), size.x(), size.y());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mightypork.utils.math.rect;
|
||||
|
||||
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
|
||||
@@ -18,31 +19,10 @@ public class RectVal extends RectView {
|
||||
* @param observed observed rect
|
||||
* @return view
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectVal make(Rect observed)
|
||||
{
|
||||
return observed.copy();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
return observed.copy(); // let the rect handle it
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +33,7 @@ public class RectVal extends RectView {
|
||||
* @param height
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectVal make(double width, double height)
|
||||
{
|
||||
return make(0, 0, width, height);
|
||||
@@ -67,6 +48,7 @@ public class RectVal extends RectView {
|
||||
* @param height
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectVal make(Vect origin, double width, double height)
|
||||
{
|
||||
return make(origin, VectVal.make(width, height));
|
||||
@@ -79,6 +61,7 @@ public class RectVal extends RectView {
|
||||
* @param size
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectVal make(Vect size)
|
||||
{
|
||||
return make(Vect.ZERO, size);
|
||||
@@ -94,6 +77,7 @@ public class RectVal extends RectView {
|
||||
* @param height
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectVal make(double x, double y, double width, double height)
|
||||
{
|
||||
return new RectVal(x, y, width, height);
|
||||
@@ -107,6 +91,7 @@ public class RectVal extends RectView {
|
||||
* @param size
|
||||
* @return new mutable rect
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static RectVal make(Vect origin, Vect size)
|
||||
{
|
||||
return make(origin.x(), origin.y(), size.x(), size.y());
|
||||
@@ -133,6 +118,7 @@ public class RectVal extends RectView {
|
||||
@Override
|
||||
public RectVal copy()
|
||||
{
|
||||
// must NOT call RectVal.make, it'd cause infinite recursion.
|
||||
return this; // nothing can change.
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mightypork.utils.math.rect;
|
||||
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
|
||||
|
||||
/**
|
||||
* Immutable rect
|
||||
@@ -14,9 +16,10 @@ public abstract class RectView extends RectMath<RectVal> {
|
||||
* @param observed observed rect
|
||||
* @return view
|
||||
*/
|
||||
@FactoryMethod
|
||||
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());
|
||||
}
|
||||
|
||||
@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
|
||||
public VectVal copy()
|
||||
{
|
||||
// must NOT call VectVal.make, it'd cause infinite recursion.
|
||||
return new VectVal(this);
|
||||
}
|
||||
|
||||
@@ -125,6 +126,8 @@ public abstract class AbstractVect implements Vect {
|
||||
@Override
|
||||
public VectView view()
|
||||
{
|
||||
// must NOT call VectView.make, it'd cause infinite recursion.
|
||||
|
||||
if (proxy == null) proxy = new VectProxy(this);
|
||||
|
||||
return proxy;
|
||||
|
||||
@@ -12,8 +12,8 @@ import mightypork.utils.math.constraints.VectBound;
|
||||
*/
|
||||
public interface Vect extends VectBound {
|
||||
|
||||
public static final VectVal ZERO = new VectVal(0, 0, 0);
|
||||
public static final VectVal ONE = new VectVal(0, 0, 0);
|
||||
VectVal ZERO = 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.Updateable;
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.math.animation.AnimDouble;
|
||||
import mightypork.utils.math.animation.Easing;
|
||||
|
||||
@@ -23,6 +24,7 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
|
||||
* @param z z animator
|
||||
* @return animated mutable vector
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectAnimated make(AnimDouble x, AnimDouble y, AnimDouble z)
|
||||
{
|
||||
return new VectAnimated(x, y, z);
|
||||
@@ -36,6 +38,7 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
|
||||
* @param easing animation easing
|
||||
* @return animated mutable vector
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectAnimated make(Vect start, Easing easing)
|
||||
{
|
||||
return new VectAnimated(start, easing);
|
||||
@@ -48,6 +51,7 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
|
||||
* @param easing animation easing
|
||||
* @return animated mutable vector
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectAnimated make(Easing 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;
|
||||
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +17,7 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
|
||||
*
|
||||
* @return new mutable vector
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectMutable zero()
|
||||
{
|
||||
return make(ZERO);
|
||||
@@ -26,6 +29,7 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
|
||||
*
|
||||
* @return one mutable vector
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectMutable one()
|
||||
{
|
||||
return make(ONE);
|
||||
@@ -39,6 +43,7 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
|
||||
* @param y Y coordinate
|
||||
* @return mutable vector
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectMutable make(double x, double y)
|
||||
{
|
||||
return make(x, y, 0);
|
||||
@@ -51,6 +56,7 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
|
||||
* @param copied copied vec
|
||||
* @return mutable vector
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectMutable make(Vect copied)
|
||||
{
|
||||
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
|
||||
* @return mutable vector
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectMutable make(double x, double y, double z)
|
||||
{
|
||||
return new VectMutableVariable(x, y, z);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mightypork.utils.math.vect;
|
||||
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
|
||||
|
||||
/**
|
||||
* Coordinate with immutable numeric values.<br>
|
||||
@@ -15,9 +17,10 @@ public final class VectVal extends VectView {
|
||||
* @param value source vector
|
||||
* @return new constant vec
|
||||
*/
|
||||
@FactoryMethod
|
||||
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
|
||||
* @return new constant vec
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectVal make(double x, double y)
|
||||
{
|
||||
return make(x, y, 0);
|
||||
@@ -42,6 +46,7 @@ public final class VectVal extends VectView {
|
||||
* @param z Z value
|
||||
* @return new constant vector
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectVal make(double x, double y, double z)
|
||||
{
|
||||
return new VectVal(x, y, z);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
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;
|
||||
|
||||
|
||||
@@ -19,9 +20,10 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
|
||||
* @param observed vector to observe
|
||||
* @return view
|
||||
*/
|
||||
@FactoryMethod
|
||||
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
|
||||
* @return view at the values
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectView make(NumBound xc, NumBound yc)
|
||||
{
|
||||
return new NumConstrVect(xc, yc);
|
||||
@@ -46,6 +49,7 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
|
||||
* @param zc Z value
|
||||
* @return view at the values
|
||||
*/
|
||||
@FactoryMethod
|
||||
public static VectView make(NumBound xc, NumBound yc, NumBound zc)
|
||||
{
|
||||
return new NumConstrVect(xc, yc, zc);
|
||||
@@ -62,6 +66,7 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
|
||||
@Override
|
||||
public VectView view()
|
||||
{
|
||||
// must NOT call VectView.copy, it'd cause infinite recursion.
|
||||
return this; // already a view
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package mightypork.utils.objects;
|
||||
|
||||
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.Calc;
|
||||
import mightypork.utils.math.Range;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
@@ -98,6 +99,7 @@ public class Convert {
|
||||
if (s.equals("true")) return true;
|
||||
if (s.equals("yes")) return true;
|
||||
if (s.equals("y")) return true;
|
||||
if (s.equals("a")) return true;
|
||||
if (s.equals("enabled")) return true;
|
||||
|
||||
if (s.equals("false")) return false;
|
||||
@@ -122,18 +124,18 @@ public class Convert {
|
||||
if (o == null) return def;
|
||||
if (o instanceof String) return ((String) o);
|
||||
|
||||
if (o instanceof Boolean) {
|
||||
return (Boolean) o ? "True" : "False";
|
||||
}
|
||||
if (o instanceof Float) return Calc.toString((float) o);
|
||||
|
||||
if (o instanceof Double) return Calc.toString((double) o);
|
||||
|
||||
if (o instanceof Vect) {
|
||||
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) {
|
||||
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<?>) {
|
||||
|
||||
Reference in New Issue
Block a user