Skip to content

Commit

Permalink
Move spinner lifetime tracking to update rather than modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Feb 5, 2025
1 parent 0ec1d06 commit 6704e56
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 87 deletions.
64 changes: 24 additions & 40 deletions src/ru/nsu/ccfit/zuev/osu/game/GameplayModernSpinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.graphics.PointF;

import com.reco1l.osu.Execution;
import com.reco1l.andengine.sprite.ExtendedSprite;
import com.reco1l.andengine.Modifiers;
import com.reco1l.andengine.Anchor;
Expand All @@ -21,59 +20,43 @@
* Created by dgsrz on 15/10/19.
*/
public class GameplayModernSpinner extends GameplaySpinner {

private final ExtendedSprite middle;
private final ExtendedSprite middle2;
private final ExtendedSprite bottom;
private final ExtendedSprite top;
private final ExtendedSprite glow;
private final ScoreNumber bonusScore;

private Scene scene;
public PointF center;
private float needRotations;
private int fullRotations = 0;
private float rotations = 0;
private boolean clear;
private int score = 1;
private StatisticV2 stat;
private PointF oldMouse;
private float duration;
private boolean spinnable;

private final PointF currMouse = new PointF();

public GameplayModernSpinner() {
ResourceManager.getInstance().checkEvoSpinnerTextures();
position.set(Constants.MAP_WIDTH / 2f, Constants.MAP_HEIGHT / 2f);
center = Utils.trackToRealCoords(position);
Utils.trackToRealCoords(position);

middle = new ExtendedSprite();
middle.setOrigin(Anchor.Center);
middle.setPosition(center.x, center.y);
middle.setPosition(position.x, position.y);
middle.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-middle"));

middle2 = new ExtendedSprite();
middle2.setOrigin(Anchor.Center);
middle2.setPosition(center.x, center.y);
middle2.setPosition(position.x, position.y);
middle2.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-middle2"));

bottom = new ExtendedSprite();
bottom.setOrigin(Anchor.Center);
bottom.setPosition(center.x, center.y);
bottom.setPosition(position.x, position.y);
bottom.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-bottom"));

top = new ExtendedSprite();
top.setOrigin(Anchor.Center);
top.setPosition(center.x, center.y);
top.setPosition(position.x, position.y);
top.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-top"));

glow = new ExtendedSprite();
glow.setOrigin(Anchor.Center);
glow.setPosition(center.x, center.y);
glow.setPosition(position.x, position.y);
glow.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-glow"));

bonusScore = new ScoreNumber(center.x, center.y + 100, "", 1.1f, true);
bonusScore = new ScoreNumber(position.x, position.y + 100, "", 1.1f, true);

// Spinners always end combo.
endsCombo = true;
Expand All @@ -96,7 +79,9 @@ public void init(final GameObjectListener listener, final Scene scene,
clear = duration <= 0f;
fullRotations = 0;
rotations = 0;
spinnable = false;

float timePreempt = (float) beatmapSpinner.timePreempt / 1000f;
passedTime = -timePreempt;

reloadHitSounds();

Expand All @@ -122,24 +107,18 @@ public void init(final GameObjectListener listener, final Scene scene,
scene.attachChild(middle);
scene.attachChild(middle2);

float timePreempt = (float) beatmapSpinner.timePreempt / 1000f;

top.registerEntityModifier(Modifiers.sequence(
Modifiers.fadeIn(timePreempt, e -> {
spinnable = true;
}),
Modifiers.delay(duration, e -> Execution.updateThread(this::removeFromScene))
));

top.registerEntityModifier(Modifiers.fadeIn(timePreempt));
bottom.registerEntityModifier(Modifiers.fadeIn(timePreempt));
middle.registerEntityModifier(Modifiers.fadeIn(timePreempt));
middle2.registerEntityModifier(Modifiers.fadeIn(timePreempt));
}

@Override
public void update(float dt) {
// Allow the spinner to fully fade in first before receiving spins.
if (!spinnable) {
passedTime += dt;

// Spinner is still in approach time.
if (passedTime < 0) {
return;
}

Expand All @@ -149,13 +128,13 @@ public void update(float dt) {
for (int i = 0, count = listener.getCursorsCount(); i < count; ++i) {
if (mouse == null) {
if (autoPlay) {
mouse = center;
mouse = position;
} else if (listener.isMouseDown(i)) {
mouse = listener.getMousePos(i);
} else {
continue;
}
currMouse.set(mouse.x - center.x, mouse.y - center.y);
currMouse.set(mouse.x - position.x, mouse.y - position.y);
}

if (oldMouse == null || listener.isMousePressed(this, i)) {
Expand Down Expand Up @@ -187,8 +166,8 @@ public void update(float dt) {
top.setRotation(degree);
//auto时,FL光圈绕中心旋转
if (GameHelper.isAutopilotMod() || GameHelper.isAuto()) {
float pX = center.x + 50 * (float) Math.sin(degree);
float pY = center.y + 50 * (float) Math.cos(degree);
float pX = position.x + 50 * (float) Math.sin(degree);
float pY = position.y + 50 * (float) Math.cos(degree);
listener.updateAutoBasedPos(pX, pY);
}
// bottom.setRotation(-degree);
Expand Down Expand Up @@ -253,8 +232,13 @@ public void update(float dt) {
}

oldMouse.set(currMouse);

if (passedTime >= duration) {
removeFromScene();
}
}

@Override
public void removeFromScene() {
glow.clearEntityModifiers();
scene.detachChild(middle);
Expand Down
99 changes: 55 additions & 44 deletions src/ru/nsu/ccfit/zuev/osu/game/GameplaySpinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.graphics.PointF;

import com.reco1l.osu.Execution;
import com.reco1l.andengine.sprite.ExtendedSprite;
import com.reco1l.andengine.Modifiers;
import com.reco1l.andengine.Anchor;
Expand All @@ -26,73 +25,76 @@
import ru.nsu.ccfit.zuev.skins.OsuSkin;

public class GameplaySpinner extends GameObject {
private final ExtendedSprite background;
public final PointF center;
private final ExtendedSprite circle;
private final ExtendedSprite approachCircle;
private final Sprite metre;
private final ExtendedSprite spinText;
private final TextureRegion metreRegion;
private final ExtendedSprite clearText;
private final ScoreNumber bonusScore;
protected Scene scene;
protected ScoreNumber bonusScore;
protected com.rian.osu.beatmap.hitobject.Spinner beatmapSpinner;
private PointF oldMouse;
protected PointF oldMouse;
protected GameObjectListener listener;
private Scene scene;
private int fullRotations = 0;
private float rotations = 0;
private float needRotations;
private boolean clear = false;
private int score = 1;
private float metreY;
private StatisticV2 stat;
private float duration;

protected int fullRotations = 0;
protected float rotations = 0;
protected float needRotations;
protected boolean clear = false;
protected int score = 1;

protected StatisticV2 stat;
protected float passedTime;
protected float duration;

protected final boolean isSpinnerFrequencyModulate;
protected GameplayHitSampleInfo[] hitSamples;
protected final GameplaySequenceHitSampleInfo spinnerSpinSample;
protected final GameplaySequenceHitSampleInfo spinnerBonusSample;

private final PointF currMouse = new PointF();
protected final PointF currMouse = new PointF();

private final ExtendedSprite background;
private final ExtendedSprite circle;
private final ExtendedSprite approachCircle;
private final Sprite metre;
private final ExtendedSprite spinText;
private final TextureRegion metreRegion;
private final ExtendedSprite clearText;
private float metreY;

public GameplaySpinner() {
ResourceManager.getInstance().checkSpinnerTextures();
position.set(Constants.MAP_WIDTH / 2f, Constants.MAP_HEIGHT / 2f);
center = Utils.trackToRealCoords(position);
Utils.trackToRealCoords(position);

background = new ExtendedSprite();
background.setOrigin(Anchor.Center);
background.setPosition(center.x, center.y);
background.setPosition(position.x, position.y);
background.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-background"));
background.setScale(Config.getRES_WIDTH() / background.getDrawWidth());

circle = new ExtendedSprite();
circle.setOrigin(Anchor.Center);
circle.setPosition(center.x, center.y);
circle.setPosition(position.x, position.y);
circle.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-circle"));

metreRegion = ResourceManager.getInstance().getTexture("spinner-metre").deepCopy();

metre = new Sprite(center.x - Config.getRES_WIDTH() / 2f, Config.getRES_HEIGHT(), metreRegion);
metre = new Sprite(position.x - Config.getRES_WIDTH() / 2f, Config.getRES_HEIGHT(), metreRegion);
metre.setWidth(Config.getRES_WIDTH());
metre.setHeight(background.getHeightScaled());

approachCircle = new ExtendedSprite();
approachCircle.setOrigin(Anchor.Center);
approachCircle.setPosition(center.x, center.y);
approachCircle.setPosition(position.x, position.y);
approachCircle.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-approachcircle"));

spinText = new ExtendedSprite();
spinText.setOrigin(Anchor.Center);
spinText.setPosition(center.x, center.y * 1.5f);
spinText.setPosition(position.x, position.y * 1.5f);
spinText.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-spin"));

clearText = new ExtendedSprite();
clearText.setOrigin(Anchor.Center);
clearText.setPosition(center.x, center.y * 0.5f);
clearText.setPosition(position.x, position.y * 0.5f);
clearText.setTextureRegion(ResourceManager.getInstance().getTexture("spinner-clear"));

bonusScore = new ScoreNumber(center.x, center.y + 100, "", 1.1f, true);
bonusScore = new ScoreNumber(position.x, position.y + 100, "", 1.1f, true);

isSpinnerFrequencyModulate = OsuSkin.get().isSpinnerFrequencyModulate();
spinnerSpinSample = new GameplaySequenceHitSampleInfo();
Expand All @@ -107,7 +109,7 @@ public void init(final GameObjectListener listener, final Scene scene,
fullRotations = 0;
rotations = 0;
this.scene = scene;
this.duration = Math.max((float) beatmapSpinner.getDuration() / 1000f, 0);
duration = Math.max((float) beatmapSpinner.getDuration() / 1000f, 0);
this.beatmapSpinner = beatmapSpinner;

needRotations = rps * duration;
Expand All @@ -125,6 +127,7 @@ public void init(final GameObjectListener listener, final Scene scene,
ResourceManager.getInstance().checkSpinnerTextures();

float timePreempt = (float) beatmapSpinner.timePreempt / 1000f;
passedTime = -timePreempt;

background.setAlpha(0);
background.registerEntityModifier(Modifiers.sequence(
Expand All @@ -147,16 +150,17 @@ public void init(final GameObjectListener listener, final Scene scene,
metreRegion.setTexturePosition(0, (int) metre.getHeightScaled());

approachCircle.setAlpha(0);
if (GameHelper.isHidden()) {
approachCircle.setVisible(false);
approachCircle.setVisible(!GameHelper.isHidden());

if (approachCircle.isVisible()) {
approachCircle.registerEntityModifier(Modifiers.sequence(
Modifiers.delay(timePreempt),
Modifiers.parallel(
Modifiers.alpha(duration, 0.75f, 1),
Modifiers.scale(duration, 2.0f, 0)
)
));
}
approachCircle.registerEntityModifier(Modifiers.sequence(e -> Execution.updateThread(this::removeFromScene),
Modifiers.delay(timePreempt),
Modifiers.parallel(
Modifiers.alpha(duration, 0.75f, 1),
Modifiers.scale(duration, 2.0f, 0)
)
));

spinText.setAlpha(0);
spinText.registerEntityModifier(Modifiers.sequence(
Expand Down Expand Up @@ -235,7 +239,10 @@ void removeFromScene() {

@Override
public void update(final float dt) {
if (circle.getAlpha() == 0) {
passedTime += dt;

// Spinner is still in approach time.
if (passedTime < 0) {
return;
}

Expand All @@ -245,13 +252,13 @@ public void update(final float dt) {
for (int i = 0, count = listener.getCursorsCount(); i < count; ++i) {
if (mouse == null) {
if (autoPlay) {
mouse = center;
mouse = position;
} else if (listener.isMouseDown(i)) {
mouse = listener.getMousePos(i);
} else {
continue;
}
currMouse.set(mouse.x - center.x, mouse.y - center.y);
currMouse.set(mouse.x - position.x, mouse.y - position.y);
}

if (oldMouse == null || listener.isMousePressed(this, i)) {
Expand Down Expand Up @@ -281,8 +288,8 @@ public void update(final float dt) {
//auto时,FL光圈绕中心旋转
if (GameHelper.isAuto() || GameHelper.isAutopilotMod()) {
float angle = (rotations + dfill / 4f) * 360;
float pX = center.x + 50 * (float)Math.sin(angle);
float pY = center.y + 50 * (float)Math.cos(angle);
float pX = position.x + 50 * (float)Math.sin(angle);
float pY = position.y + 50 * (float)Math.cos(angle);
listener.updateAutoBasedPos(pX, pY);
}
}
Expand Down Expand Up @@ -338,6 +345,10 @@ public void update(final float dt) {
(int) (metre.getBaseHeight() * (1 - Math.abs(percentfill))));

oldMouse.set(currMouse);

if (passedTime >= duration) {
removeFromScene();
}
}

protected void reloadHitSounds() {
Expand Down
5 changes: 2 additions & 3 deletions src/ru/nsu/ccfit/zuev/osu/game/cursor/main/AutoCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ public void moveToObject(GameObject object, float secPassed, GameObjectListener
float movePositionY = object.getPosition().y;
float deltaT = object.getHitTime() - secPassed;

if (object instanceof GameplaySpinner spinner) {
movePositionX = spinner.center.x;
movePositionY = spinner.center.y + 50;
if (object instanceof GameplaySpinner) {
movePositionY += 50;
}

currentObjectId = object.getId();
Expand Down

0 comments on commit 6704e56

Please sign in to comment.