Use java.awt.Point in Cursor class instead of separate x/y lists.
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -26,8 +26,8 @@ import itdelatrisu.opsu.Utils;
|
|||||||
import itdelatrisu.opsu.skins.Skin;
|
import itdelatrisu.opsu.skins.Skin;
|
||||||
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
@@ -46,7 +46,7 @@ public class Cursor {
|
|||||||
private static org.lwjgl.input.Cursor emptyCursor;
|
private static org.lwjgl.input.Cursor emptyCursor;
|
||||||
|
|
||||||
/** Last cursor coordinates. */
|
/** Last cursor coordinates. */
|
||||||
private int lastX = -1, lastY = -1;
|
private Point lastPosition;
|
||||||
|
|
||||||
/** Cursor rotation angle. */
|
/** Cursor rotation angle. */
|
||||||
private float cursorAngle = 0f;
|
private float cursorAngle = 0f;
|
||||||
@@ -64,7 +64,7 @@ public class Cursor {
|
|||||||
private static final float CURSOR_SCALE_TIME = 125;
|
private static final float CURSOR_SCALE_TIME = 125;
|
||||||
|
|
||||||
/** Stores all previous cursor locations to display a trail. */
|
/** Stores all previous cursor locations to display a trail. */
|
||||||
private LinkedList<Integer> cursorX, cursorY;
|
private LinkedList<Point> trail = new LinkedList<Point>();
|
||||||
|
|
||||||
// game-related variables
|
// game-related variables
|
||||||
private static GameContainer container;
|
private static GameContainer container;
|
||||||
@@ -94,10 +94,7 @@ public class Cursor {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public Cursor() {
|
public Cursor() {}
|
||||||
cursorX = new LinkedList<Integer>();
|
|
||||||
cursorY = new LinkedList<Integer>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the cursor.
|
* Draws the cursor.
|
||||||
@@ -161,48 +158,38 @@ public class Cursor {
|
|||||||
float FPSmod = Math.max(container.getFPS(), 1) / 60f;
|
float FPSmod = Math.max(container.getFPS(), 1) / 60f;
|
||||||
if (newStyle) {
|
if (newStyle) {
|
||||||
// new style: add all points between cursor movements
|
// new style: add all points between cursor movements
|
||||||
if (lastX < 0) {
|
if (lastPosition == null) {
|
||||||
lastX = mouseX;
|
lastPosition = new Point(mouseX, mouseY);
|
||||||
lastY = mouseY;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addCursorPoints(lastX, lastY, mouseX, mouseY);
|
addCursorPoints(lastPosition.x, lastPosition.y, mouseX, mouseY);
|
||||||
lastX = mouseX;
|
lastPosition.move(mouseX, mouseY);
|
||||||
lastY = mouseY;
|
|
||||||
|
|
||||||
removeCount = (int) (cursorX.size() / (6 * FPSmod)) + 1;
|
removeCount = (int) (trail.size() / (6 * FPSmod)) + 1;
|
||||||
} else {
|
} else {
|
||||||
// old style: sample one point at a time
|
// old style: sample one point at a time
|
||||||
cursorX.add(mouseX);
|
trail.add(new Point(mouseX, mouseY));
|
||||||
cursorY.add(mouseY);
|
|
||||||
|
|
||||||
int max = (int) (10 * FPSmod);
|
int max = (int) (10 * FPSmod);
|
||||||
if (cursorX.size() > max)
|
if (trail.size() > max)
|
||||||
removeCount = cursorX.size() - max;
|
removeCount = trail.size() - max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove points from the lists
|
// remove points from the lists
|
||||||
for (int i = 0; i < removeCount && !cursorX.isEmpty(); i++) {
|
for (int i = 0; i < removeCount && !trail.isEmpty(); i++)
|
||||||
cursorX.remove();
|
trail.remove();
|
||||||
cursorY.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw a fading trail
|
// draw a fading trail
|
||||||
float alpha = 0f;
|
float alpha = 0f;
|
||||||
float t = 2f / cursorX.size();
|
float t = 2f / trail.size();
|
||||||
int cursorTrailWidth = cursorTrail.getWidth(), cursorTrailHeight = cursorTrail.getHeight();
|
int cursorTrailWidth = cursorTrail.getWidth(), cursorTrailHeight = cursorTrail.getHeight();
|
||||||
float cursorTrailRotation = (skin.isCursorTrailRotated()) ? cursorAngle : 0;
|
float cursorTrailRotation = (skin.isCursorTrailRotated()) ? cursorAngle : 0;
|
||||||
Iterator<Integer> iterX = cursorX.iterator();
|
|
||||||
Iterator<Integer> iterY = cursorY.iterator();
|
|
||||||
cursorTrail.startUse();
|
cursorTrail.startUse();
|
||||||
while (iterX.hasNext()) {
|
for (Point p : trail) {
|
||||||
int cx = iterX.next();
|
|
||||||
int cy = iterY.next();
|
|
||||||
alpha += t;
|
alpha += t;
|
||||||
cursorTrail.setImageColor(1f, 1f, 1f, alpha);
|
cursorTrail.setImageColor(1f, 1f, 1f, alpha);
|
||||||
// if (cx != x || cy != y)
|
|
||||||
cursorTrail.drawEmbedded(
|
cursorTrail.drawEmbedded(
|
||||||
cx - (cursorTrailWidth / 2f), cy - (cursorTrailHeight / 2f),
|
p.x - (cursorTrailWidth / 2f), p.y - (cursorTrailHeight / 2f),
|
||||||
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation);
|
cursorTrailWidth, cursorTrailHeight, cursorTrailRotation);
|
||||||
}
|
}
|
||||||
cursorTrail.drawEmbedded(
|
cursorTrail.drawEmbedded(
|
||||||
@@ -237,8 +224,7 @@ public class Cursor {
|
|||||||
if (dy <= dx) {
|
if (dy <= dx) {
|
||||||
for (int i = 0; ; i++) {
|
for (int i = 0; ; i++) {
|
||||||
if (i == k) {
|
if (i == k) {
|
||||||
cursorX.add(x1);
|
trail.add(new Point(x1, y1));
|
||||||
cursorY.add(y1);
|
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
if (x1 == x2)
|
if (x1 == x2)
|
||||||
@@ -253,8 +239,7 @@ public class Cursor {
|
|||||||
} else {
|
} else {
|
||||||
for (int i = 0; ; i++) {
|
for (int i = 0; ; i++) {
|
||||||
if (i == k) {
|
if (i == k) {
|
||||||
cursorX.add(x1);
|
trail.add(new Point(x1, y1));
|
||||||
cursorY.add(y1);
|
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
if (y1 == y2)
|
if (y1 == y2)
|
||||||
@@ -301,9 +286,8 @@ public class Cursor {
|
|||||||
* Resets all cursor location data.
|
* Resets all cursor location data.
|
||||||
*/
|
*/
|
||||||
public void resetLocations() {
|
public void resetLocations() {
|
||||||
lastX = lastY = -1;
|
lastPosition = null;
|
||||||
cursorX.clear();
|
trail.clear();
|
||||||
cursorY.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user