Refactoring and polishing of the constraint system

Now it will be clear what is VALUE, VIEW and MUTABLE.
This commit is contained in:
Ondřej Hruška
2014-04-12 23:24:49 +02:00
parent 4221d5430a
commit 4816e0b539
65 changed files with 1169 additions and 1297 deletions
@@ -6,7 +6,7 @@ import java.io.IOException;
import mightypork.gamecore.loading.DeferredResource;
import mightypork.utils.files.FileUtils;
import mightypork.utils.logging.LoggedName;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.vect.Vect;
import org.newdawn.slick.openal.Audio;
import org.newdawn.slick.openal.SoundStore;
@@ -204,7 +204,7 @@ public class DeferredAudio extends DeferredResource {
* @param pos coord
* @return source id
*/
public int playAsEffect(double pitch, double gain, boolean loop, Vec pos)
public int playAsEffect(double pitch, double gain, boolean loop, Vect pos)
{
if (!ensureLoaded()) return -1;
@@ -12,9 +12,9 @@ import mightypork.gamecore.control.bus.clients.RootBusNode;
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
import mightypork.gamecore.control.timing.Updateable;
import mightypork.utils.math.Calc.Buffers;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecMutable;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectView;
import org.lwjgl.openal.AL;
import org.lwjgl.openal.AL10;
@@ -28,10 +28,10 @@ import org.newdawn.slick.openal.SoundStore;
*/
public class SoundSystem extends RootBusNode implements Updateable {
private static final Vec INITIAL_LISTENER_POS = Vec.ZERO;
private static final Vect INITIAL_LISTENER_POS = Vect.ZERO;
private static final int MAX_SOURCES = 256;
private static VecMutable listener = VecMutable.zero();
private static VectMutable listener = VectMutable.zero();
private static boolean soundSystemInited = false;
@@ -40,7 +40,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
*
* @param pos
*/
public static void setListener(Vec pos)
public static void setListener(Vect pos)
{
listener.setTo(pos);
final FloatBuffer buf3 = Buffers.alloc(3);
@@ -60,7 +60,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
/**
* @return listener coordinate
*/
public static VecView getListener()
public static VectView getListener()
{
return listener.view();
}
@@ -3,7 +3,7 @@ package mightypork.gamecore.audio.players;
import mightypork.gamecore.audio.DeferredAudio;
import mightypork.gamecore.audio.Volume;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.vect.Vect;
/**
@@ -59,7 +59,7 @@ public class EffectPlayer extends BaseAudioPlayer {
* @param pos play position
* @return source id
*/
public int play(double pitch, double gain, Vec pos)
public int play(double pitch, double gain, Vect pos)
{
if (!hasAudio()) return -1;
@@ -2,8 +2,8 @@ package mightypork.gamecore.control.bus.events;
import mightypork.utils.math.constraints.RectConstraint;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@@ -19,7 +19,7 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
private final int button;
private final int wheeld;
private final Vec pos;
private final Vect pos;
private final boolean down;
@@ -31,7 +31,7 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
* @param down button pressed
* @param wheeld wheel change
*/
public MouseButtonEvent(Vec pos, int button, boolean down, int wheeld) {
public MouseButtonEvent(Vect pos, int button, boolean down, int wheeld) {
this.button = button;
this.down = down;
this.pos = pos;
@@ -78,7 +78,7 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
/**
* @return mouse position when the event occurred
*/
public VecView getPos()
public VectView getPos()
{
return pos.view();
}
@@ -2,8 +2,8 @@ package mightypork.gamecore.control.bus.events;
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@@ -14,15 +14,15 @@ import mightypork.utils.math.coord.VecView;
@UnloggedEvent
public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
private final VecView move;
private final VecView pos;
private final VectView move;
private final VectView pos;
/**
* @param pos end pos
* @param move move vector
*/
public MouseMotionEvent(Vec pos, Vec move) {
public MouseMotionEvent(Vect pos, Vect move) {
this.move = move.value();
this.pos = pos.value();
}
@@ -31,7 +31,7 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
/**
* @return movement since last {@link MouseMotionEvent}
*/
public VecView getMove()
public VectView getMove()
{
return move;
}
@@ -40,7 +40,7 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
/**
* @return current mouse position
*/
public VecView getPos()
public VectView getPos()
{
return pos;
}
@@ -1,8 +1,8 @@
package mightypork.gamecore.control.bus.events;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@@ -13,7 +13,7 @@ import mightypork.utils.math.coord.VecView;
public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
private final boolean fullscreen;
private final Vec screenSize;
private final Vect screenSize;
private final boolean fsChanged;
@@ -22,7 +22,7 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
* @param fullscreen is now fullscreen
* @param size new screen size
*/
public ScreenChangeEvent(boolean fsChanged, boolean fullscreen, Vec size) {
public ScreenChangeEvent(boolean fsChanged, boolean fullscreen, Vect size) {
this.fullscreen = fullscreen;
this.screenSize = size;
this.fsChanged = fsChanged;
@@ -50,7 +50,7 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
/**
* @return new screen size
*/
public VecView getScreenSize()
public VectView getScreenSize()
{
return screenSize.view();
}
@@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components;
import mightypork.utils.math.constraints.PluggableRect;
import mightypork.utils.math.constraints.RectConstraint;
import mightypork.utils.math.rect.RectValue;
import mightypork.utils.math.rect.RectView;
/**
@@ -18,7 +18,7 @@ public interface PluggableRenderable extends Renderable, PluggableRect {
@Override
RectValue getRect();
RectView getRect();
@Override
@@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components;
import mightypork.utils.math.constraints.ContextAdapter;
import mightypork.utils.math.constraints.RectConstraint;
import mightypork.utils.math.rect.RectValue;
import mightypork.utils.math.rect.RectView;
/**
@@ -18,7 +18,7 @@ public abstract class PluggableRenderer extends ContextAdapter implements Plugga
@Override
public RectValue getRect()
public RectView getRect()
{
return super.getRect();
}
@@ -10,7 +10,7 @@ import mightypork.gamecore.gui.components.PluggableRenderable;
import mightypork.gamecore.gui.components.PluggableRenderer;
import mightypork.gamecore.gui.components.Renderable;
import mightypork.utils.math.constraints.RectConstraint;
import mightypork.utils.math.rect.RectValue;
import mightypork.utils.math.rect.RectView;
/**
@@ -60,7 +60,7 @@ public abstract class ElementHolder extends BusNode implements PluggableRenderab
@Override
public RectValue getRect()
public RectView getRect()
{
return context.getRect();
}
@@ -6,9 +6,9 @@ import mightypork.gamecore.render.fonts.FontRenderer;
import mightypork.gamecore.render.fonts.FontRenderer.Align;
import mightypork.gamecore.render.fonts.GLFont;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecMutable;
import mightypork.utils.math.rect.RectValue;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.string.StringProvider;
import mightypork.utils.string.StringProvider.StringWrapper;
@@ -29,7 +29,7 @@ public class TextPainter extends PluggableRenderer {
private boolean shadow;
private RGB shadowColor = RGB.BLACK;
private final VecMutable shadowOffset = VecMutable.make(1, 1);
private final VectMutable shadowOffset = VectMutable.make(1, 1);
/**
@@ -85,7 +85,7 @@ public class TextPainter extends PluggableRenderer {
if (text == null) return;
final String str = text.getString();
final RectValue rect = getRect();
final RectView rect = getRect();
if (shadow) {
font.draw(str, rect.move(shadowOffset), align, shadowColor);
@@ -94,7 +94,7 @@ public class TextPainter extends PluggableRenderer {
}
public void setShadow(RGB color, Vec offset)
public void setShadow(RGB color, Vect offset)
{
setShadow(true);
setShadowColor(color);
@@ -114,7 +114,7 @@ public class TextPainter extends PluggableRenderer {
}
public void setShadowOffset(Vec shadowOffset)
public void setShadowOffset(Vect shadowOffset)
{
this.shadowOffset.setTo(shadowOffset);
}
@@ -5,7 +5,7 @@ import java.util.Collection;
import java.util.TreeSet;
import mightypork.gamecore.control.AppAccess;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.vect.Vect;
/**
@@ -79,7 +79,7 @@ public abstract class LayeredScreen extends Screen {
@Override
protected void onSizeChanged(Vec size)
protected void onSizeChanged(Vect size)
{
for (final ScreenLayer layer : layers) {
layer.onSizeChanged(size);
@@ -11,8 +11,8 @@ import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.render.Render;
import mightypork.utils.math.constraints.RectConstraint;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.rect.RectValue;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.Vect;
/**
@@ -104,7 +104,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
@Override
public RectValue getRect()
public RectView getRect()
{
return getDisplay().getRect();
}
@@ -153,7 +153,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
* @param size screen size
*/
@DefaultImpl
protected void onSizeChanged(Vec size)
protected void onSizeChanged(Vect size)
{
//
}
@@ -8,9 +8,9 @@ import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.utils.math.constraints.RectConstraint;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.rect.RectValue;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@@ -27,9 +27,9 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
private final KeyBindingPool keybindings = new KeyBindingPool();
/** Mouse position constraint */
protected final VecView cMousePos = getInput().getMousePos();
protected final VectView cMousePos = getInput().getMousePos();
/** Screen size constraint */
protected final VecView cScreenSize = getDisplay().getSize();
protected final VectView cScreenSize = getDisplay().getSize();
/**
@@ -67,7 +67,7 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
@Override
public RectValue getRect()
public RectView getRect()
{
return screen.getRect();
}
@@ -118,7 +118,7 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
* @param size screen size
*/
@DefaultImpl
protected void onSizeChanged(Vec size)
protected void onSizeChanged(Vect size)
{
//
}
@@ -9,8 +9,8 @@ import mightypork.gamecore.control.bus.events.MouseMotionEvent;
import mightypork.gamecore.control.timing.Updateable;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
import mightypork.utils.math.coord.VecMutable;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectView;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
@@ -29,7 +29,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
private final KeyBindingPool keybindings;
/** Current mouse position */
private final VecView mousePos = new VecView() {
private final VectView mousePos = new VectView() {
@Override
public double x()
@@ -103,8 +103,8 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
}
// counters as fields to save memory.
private final VecMutable mouseMove = VecMutable.zero();
private final VecMutable mouseLastPos = VecMutable.zero();
private final VectMutable mouseMove = VectMutable.zero();
private final VectMutable mouseLastPos = VectMutable.zero();
@Override
@@ -140,13 +140,13 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
}
private void onMouseEvent(VecMutable moveSum, VecMutable lastPos)
private void onMouseEvent(VectMutable moveSum, VectMutable lastPos)
{
final int button = Mouse.getEventButton();
final boolean down = Mouse.getEventButtonState();
final VecMutable pos = VecMutable.make(Mouse.getEventX(), Mouse.getEventY());
final VecMutable move = VecMutable.make(Mouse.getEventDX(), Mouse.getEventDY());
final VectMutable pos = VectMutable.make(Mouse.getEventX(), Mouse.getEventY());
final VectMutable move = VectMutable.make(Mouse.getEventDX(), Mouse.getEventDY());
final int wheeld = Mouse.getEventDWheel();
@@ -178,7 +178,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
*
* @return mouse position
*/
public VecView getMousePos()
public VectView getMousePos()
{
return mousePos;
}
@@ -11,8 +11,9 @@ import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
import mightypork.gamecore.control.timing.FpsMeter;
import mightypork.utils.logging.Log;
import mightypork.utils.math.constraints.RectConstraint;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.rect.RectValue;
import mightypork.utils.math.rect.RectVal;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.VectView;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
@@ -32,7 +33,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
private FpsMeter fpsMeter;
/** Current screen size */
private final VecView screenSize = new VecView() {
private final VectView screenSize = new VectView() {
@Override
public double y()
@@ -188,7 +189,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
*
* @return size
*/
public VecView getSize()
public VectView getSize()
{
return screenSize;
}
@@ -239,9 +240,9 @@ public class DisplaySystem extends AppModule implements RectConstraint {
@Override
public RectValue getRect()
public RectView getRect()
{
return RectValue.make(getSize());
return RectVal.make(getSize());
}
@@ -254,7 +255,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
}
public VecView getCenter()
public VectView getCenter()
{
return getSize().half();
}
+11 -10
View File
@@ -9,9 +9,10 @@ import mightypork.gamecore.render.textures.TxQuad;
import mightypork.utils.files.FileUtils;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
@@ -27,9 +28,9 @@ import org.newdawn.slick.util.ResourceLoader;
*/
public class Render {
public static final VecView AXIS_X = VecView.make(1, 0, 0);
public static final VecView AXIS_Y = VecView.make(0, 1, 0);
public static final VecView AXIS_Z = VecView.make(0, 0, 1);
public static final VectView AXIS_X = VectVal.make(1, 0, 0);
public static final VectView AXIS_Y = VectVal.make(0, 1, 0);
public static final VectView AXIS_Z = VectVal.make(0, 0, 1);
/**
@@ -85,7 +86,7 @@ public class Render {
*
* @param coord coord
*/
public static void translate(Vec coord)
public static void translate(Vect coord)
{
glTranslated(coord.x(), coord.y(), coord.z());
}
@@ -121,7 +122,7 @@ public class Render {
*
* @param factor vector of scaling factors
*/
public static void scale(Vec factor)
public static void scale(Vect factor)
{
glScaled(factor.x(), factor.y(), factor.z());
}
@@ -210,9 +211,9 @@ public class Render {
* @param angle rotate angle
* @param axis rotation axis
*/
public static void rotate(double angle, Vec axis)
public static void rotate(double angle, Vect axis)
{
final Vec vec = axis.view().norm(1);
final Vect vec = axis.view().norm(1);
glRotated(angle, vec.x(), vec.y(), vec.z());
}
@@ -543,7 +544,7 @@ public class Render {
*
* @param size viewport size (screen size)
*/
public static void setupOrtho(VecView size)
public static void setupOrtho(VectView size)
{
// fix projection for changed size
glMatrixMode(GL_PROJECTION);
@@ -3,10 +3,10 @@ package mightypork.gamecore.render.fonts;
import mightypork.gamecore.render.Render;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecMutable;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectView;
/**
@@ -51,7 +51,7 @@ public class FontRenderer {
* @param height drawing height
* @return taken space (width, height)
*/
public Vec getNeededSpace(String text, double height)
public Vect getNeededSpace(String text, double height)
{
return font.getNeededSpace(text).mul(getScale(height));
}
@@ -106,7 +106,7 @@ public class FontRenderer {
* @param height drawing height
* @param color drawing color
*/
public void draw(String text, Vec pos, double height, RGB color)
public void draw(String text, Vect pos, double height, RGB color)
{
Render.pushMatrix();
@@ -144,7 +144,7 @@ public class FontRenderer {
*/
public void draw(String text, Rect bounds, Align align, RGB color)
{
VecView start;
VectView start;
switch (align) {
case LEFT:
@@ -173,7 +173,7 @@ public class FontRenderer {
* @param height drawing height
* @param align horizontal alignment
*/
public void draw(String text, Vec pos, double height, Align align)
public void draw(String text, Vect pos, double height, Align align)
{
draw(text, pos, height, align, this.color);
}
@@ -188,12 +188,12 @@ public class FontRenderer {
* @param align horizontal alignment
* @param color drawing color
*/
public void draw(String text, Vec pos, double height, Align align, RGB color)
public void draw(String text, Vect pos, double height, Align align, RGB color)
{
final double w = getWidth(text, height);
final VecMutable start = pos.mutable();
final VectMutable start = pos.mutable();
switch (align) {
case LEFT:
@@ -2,7 +2,7 @@ package mightypork.gamecore.render.fonts;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.vect.VectView;
/**
@@ -27,7 +27,7 @@ public interface GLFont {
* @param text string to check
* @return coord (width, height)
*/
VecView getNeededSpace(String text);
VectView getNeededSpace(String text);
/**
@@ -23,7 +23,8 @@ import mightypork.gamecore.render.fonts.GLFont;
import mightypork.gamecore.render.textures.FilterMode;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
import org.lwjgl.BufferUtils;
import org.lwjgl.util.glu.GLU;
@@ -422,9 +423,9 @@ public class CachedFont implements GLFont {
@Override
public VecView getNeededSpace(String text)
public VectVal getNeededSpace(String text)
{
return VecView.make(getWidth(text), getLineHeight());
return VectVal.make(getWidth(text), getLineHeight());
}
}
@@ -13,8 +13,8 @@ import mightypork.gamecore.render.textures.FilterMode;
import mightypork.utils.files.FileUtils;
import mightypork.utils.logging.LoggedName;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@@ -164,9 +164,9 @@ public class DeferredFont extends DeferredResource implements GLFont {
* @return coord (width, height)
*/
@Override
public VecView getNeededSpace(String text)
public VectView getNeededSpace(String text)
{
if (!ensureLoaded()) return Vec.ZERO;
if (!ensureLoaded()) return Vect.ZERO;
return font.getNeededSpace(text);
}
@@ -4,8 +4,8 @@ package mightypork.gamecore.render.fonts.impl;
import mightypork.gamecore.render.fonts.GLFont;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.Vec;
import mightypork.utils.math.coord.VecView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@@ -23,9 +23,9 @@ public class NullFont implements GLFont {
@Override
public VecView getNeededSpace(String str)
public VectView getNeededSpace(String str)
{
return Vec.ZERO;
return Vect.ZERO;
}
@@ -2,7 +2,7 @@ package mightypork.gamecore.render.textures;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.rect.RectValue;
import mightypork.utils.math.rect.RectVal;
import org.newdawn.slick.opengl.Texture;
@@ -65,7 +65,7 @@ public class TxQuad {
* @param y2 right bottom Y (0-1)
*/
public TxQuad(Texture tx, double x1, double y1, double x2, double y2) {
this(tx, RectValue.make(x1, y1, x2, y2));
this(tx, RectVal.make(x1, y1, x2, y2));
}