Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement osu!stable fail animation #453

Merged
merged 17 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions src/com/edlplan/andengine/TriangleBuilder.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.edlplan.andengine;

import com.edlplan.framework.math.Vec2;
import com.edlplan.framework.math.Vec3;
import com.edlplan.framework.utils.FloatArraySlice;

import java.util.Arrays;

public class TriangleBuilder extends FloatArraySlice {

public TriangleBuilder(float[] cache) {
this.ary = cache;
}

public float maxX = 0f;

public float maxY = 0f;


public TriangleBuilder() {
this(1);
Expand All @@ -20,17 +21,6 @@ public TriangleBuilder(int size) {
ary = new float[6 * size];
}

public void add(Vec3 p1, Vec3 p2, Vec3 p3) {
if (length + 6 > ary.length) {
ary = Arrays.copyOf(ary, ary.length * 3 / 2 + 6);
}
ary[length++] = p1.x;
ary[length++] = p1.y;
ary[length++] = p2.x;
ary[length++] = p2.y;
ary[length++] = p3.x;
ary[length++] = p3.y;
}

public void add(Vec2 p1, Vec2 p2, Vec2 p3) {
if (length + 6 > ary.length) {
Expand All @@ -42,21 +32,30 @@ public void add(Vec2 p1, Vec2 p2, Vec2 p3) {
ary[length++] = p2.y;
ary[length++] = p3.x;
ary[length++] = p3.y;
}

public float[] copyVertex() {
float[] c = Arrays.copyOf(ary, offset);
return c;
if (p1.x > maxX) maxX = p1.x;
if (p2.x > maxX) maxX = p2.x;
if (p3.x > maxX) maxX = p3.x;

if (p1.y > maxY) maxY = p1.y;
if (p2.y > maxY) maxY = p2.y;
if (p3.y > maxY) maxY = p3.y;
}

public FloatArraySlice getVertex(FloatArraySlice slice) {
public void applyVertices(FloatArraySlice slice) {
slice.offset = 0;
if (slice.ary.length < length) {
slice.ary = new float[length];
}
slice.length = length;
System.arraycopy(ary, 0, slice.ary, 0, length);
return slice;
}

public void reset() {
length = 0;
maxX = 0f;
maxY = 0f;
}


}
28 changes: 4 additions & 24 deletions src/com/edlplan/osu/support/slider/DrawLinePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
public class DrawLinePath {
private static final int MAXRES = 24;

private static final float Z_MIDDLE = 99.0f;

private static final float Z_SIDE = -99.0f;
public float alpha;
public float width;
Vec2 current, current2;
Expand All @@ -24,12 +21,6 @@ public class DrawLinePath {
private TriangleBuilder triangles;
private AbstractPath path;

public DrawLinePath(AbstractPath p, float width) {
alpha = 1;
path = p;
this.width = width;
}

public DrawLinePath() {
alpha = 1;
}
Expand All @@ -44,21 +35,13 @@ public DrawLinePath reset(AbstractPath p, float width) {
return this;
}

public TriangleBuilder getTriangles() {
if (triangles == null) {
triangles = new TriangleBuilder(path.size() * 6);
init();
}
return triangles;
}

public TriangleBuilder getTriangles(TriangleBuilder builder) {
public TriangleBuilder computeTriangles(TriangleBuilder builder) {
TriangleBuilder cache = triangles;
if (cache != null) {
cache.getVertex(builder);
cache.applyVertices(builder);
} else {
triangles = builder;
builder.length = 0;
builder.reset();
init();
}
triangles = cache;
Expand Down Expand Up @@ -136,11 +119,8 @@ private void init() {
if (path.size() == 1) {
addLineCap(path.get(0), FMath.Pi, FMath.Pi);
addLineCap(path.get(0), 0, FMath.Pi);
return;
} else {
return;
//throw new RuntimeException("Path must has at least 1 point");
}
return;
}

float theta = Vec2.calTheta(path.get(0), path.get(1));
Expand Down
32 changes: 21 additions & 11 deletions src/com/edlplan/osu/support/slider/SliderBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.edlplan.framework.math.line.LinePath;
import com.reco1l.andengine.shape.TriangleMesh;
import com.reco1l.andengine.container.Container;
import com.rian.osu.math.Vector2;


public class SliderBody extends Container {
Expand Down Expand Up @@ -59,7 +60,7 @@ public SliderBody(boolean allowHint) {
}


public void setPath(LinePath path, boolean beginEmpty) {
public void init(LinePath path, boolean beginEmpty, Vector2 position) {

reset();
this.path = path;
Expand All @@ -73,6 +74,7 @@ public void setPath(LinePath path, boolean beginEmpty) {
}

shouldRebuildVertices = true;
setPosition(position.x, position.y);
}


Expand Down Expand Up @@ -114,24 +116,32 @@ public void setBorderColor(float r, float g, float b) {
}


private void buildVertices(LinePath sub) {
private void buildVertices(LinePath subPath) {

TriangleBuilder builder = buildCache.triangleBuilder;

if (hint != null && hint.isVisible()) {
buildCache.drawLinePath
.reset(sub, Math.min(hintWidth, backgroundWidth - borderWidth))
.getTriangles(buildCache.triangleBuilder)
.getVertex(hint.getVertices());
.reset(subPath, Math.min(hintWidth, backgroundWidth - borderWidth))
.computeTriangles(builder)
.applyVertices(hint.getVertices());

hint.setContentSize(builder.maxX, builder.maxY);
}

buildCache.drawLinePath
.reset(sub, backgroundWidth - borderWidth)
.getTriangles(buildCache.triangleBuilder)
.getVertex(background.getVertices());
.reset(subPath, backgroundWidth - borderWidth)
.computeTriangles(builder)
.applyVertices(background.getVertices());

background.setContentSize(builder.maxX, builder.maxY);

buildCache.drawLinePath
.reset(sub, backgroundWidth)
.getTriangles(buildCache.triangleBuilder)
.getVertex(border.getVertices());
.reset(subPath, backgroundWidth)
.computeTriangles(builder)
.applyVertices(border.getVertices());

border.setContentSize(builder.maxX, builder.maxY);
}


Expand Down
10 changes: 10 additions & 0 deletions src/com/reco1l/andengine/ExtendedEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ abstract class ExtendedEntity(
}
}

open fun setTranslation(x: Float, y: Float) {
translationX = x
translationY = y
}


// Drawing

Expand Down Expand Up @@ -318,6 +323,11 @@ abstract class ExtendedEntity(
blue *= parent.blue
alpha *= parent.alpha

// We'll assume at this point there's no need to keep multiplying.
if (red == 0f || green == 0f || blue == 0f || alpha == 0f) {
break
}

parent = parent.parent
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/com/reco1l/andengine/shape/TriangleMesh.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@ class TriangleMesh : ExtendedEntity(vertexBuffer = null) {
*/
val vertices = FloatArraySlice()


init {
isCullingEnabled = false
vertices.ary = FloatArray(0)
}


/**
* Allows to set the content size of the mesh explicitly.
*/
fun setContentSize(width: Float, height: Float) {
contentWidth = width
contentHeight = height
onContentSizeMeasured()
}


override fun onInitDraw(pGL: GL10) {

super.onInitDraw(pGL)
Expand Down
15 changes: 8 additions & 7 deletions src/com/reco1l/osu/hitobjects/SliderTicks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ class SliderTickContainer : Container() {

detachChildren()

val scale = beatmapSlider.gameplayScale
val position = beatmapSlider.gameplayStackedPosition

for (i in 1 until beatmapSlider.nestedHitObjects.size) {

val sliderTick = beatmapSlider.nestedHitObjects[i] as? SliderTick ?: break
val position = sliderTick.gameplayStackedPosition
val sprite = SliderTickSprite.pool.obtain()
val tick = beatmapSlider.nestedHitObjects[i] as? SliderTick ?: break
val tickPosition = tick.gameplayStackedPosition

sprite.setPosition(position.x, position.y)
sprite.setScale(scale)
val sprite = SliderTickSprite.pool.obtain()
sprite.alpha = 0f

// We're substracting the position of the slider because the tick container is
// already at the position of the slider since it's a child of the slider's body.
sprite.setPosition(tickPosition.x - position.x, tickPosition.y - position.y)

attachChild(sprite)
}

}

override fun onDetached() {
Expand Down
27 changes: 25 additions & 2 deletions src/ru/nsu/ccfit/zuev/audio/serviceAudio/BassAudioFunc.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class BassAudioFunc {
private BroadcastReceiver receiver;
private LocalBroadcastManager broadcastManager;

/**
* The channel's frequency, in Hz.
*/
private float frequency;

/**
* Whether the game is currently on focus.
*/
Expand Down Expand Up @@ -105,6 +110,8 @@ public boolean preLoad(String filePath, float speed, boolean adjustPitch) {
}

BASS.BASS_ChannelGetInfo(channel, channelInfo);
frequency = channelInfo.freq;

setSpeed(speed);
setAdjustPitch(adjustPitch);

Expand Down Expand Up @@ -218,6 +225,19 @@ public void setAdjustPitch(boolean adjustPitch) {
onAudioEffectChange();
}

public void setFrequencyForcefully(float frequency) {
if (channel == 0) {
return;
}
this.frequency = frequency;
BASS.BASS_ChannelSetAttribute(channel, BASS_FX.BASS_ATTRIB_TEMPO_FREQ, frequency);
BASS.BASS_ChannelSetAttribute(channel, BASS_FX.BASS_ATTRIB_TEMPO, 0);
}

public float getFrequency() {
return frequency;
}

public float getVolume() {
BASS.FloatValue volume = new BASS.FloatValue();
if (channel != 0) {
Expand Down Expand Up @@ -268,11 +288,14 @@ private void onAudioEffectChange() {
return;
}


if (adjustPitch) {
BASS.BASS_ChannelSetAttribute(channel, BASS_FX.BASS_ATTRIB_TEMPO_FREQ, channelInfo.freq * speed);
frequency = channelInfo.freq * speed;
BASS.BASS_ChannelSetAttribute(channel, BASS_FX.BASS_ATTRIB_TEMPO_FREQ, frequency);
BASS.BASS_ChannelSetAttribute(channel, BASS_FX.BASS_ATTRIB_TEMPO, 0);
} else {
BASS.BASS_ChannelSetAttribute(channel, BASS_FX.BASS_ATTRIB_TEMPO_FREQ, channelInfo.freq);
frequency = channelInfo.freq;
BASS.BASS_ChannelSetAttribute(channel, BASS_FX.BASS_ATTRIB_TEMPO_FREQ, frequency);
BASS.BASS_ChannelSetAttribute(channel, BASS_FX.BASS_ATTRIB_TEMPO, (speed - 1) * 100);
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/ru/nsu/ccfit/zuev/audio/serviceAudio/SongService.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ public void setAdjustPitch(boolean adjustPitch) {
}
}

public void setFrequencyForcefully(float frequency) {
if (audioFunc != null) {
audioFunc.setFrequencyForcefully(frequency);
}
}

public float getFrequency() {
if (audioFunc != null) {
return audioFunc.getFrequency();
}
return 0f;
}

public void showNotification() {
if (this.isGaming) {
Log.w("SongService", "NOT SHOW THE NOTIFY CUZ IS GAMING");
Expand Down
14 changes: 5 additions & 9 deletions src/ru/nsu/ccfit/zuev/osu/game/GameHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.math.RoundingMode;
import java.util.Arrays;

import ru.nsu.ccfit.zuev.osu.Constants;
import ru.nsu.ccfit.zuev.skins.OsuSkin;
import ru.nsu.ccfit.zuev.osu.Utils;
import ru.nsu.ccfit.zuev.osu.helper.DifficultyHelper;
Expand Down Expand Up @@ -98,23 +99,18 @@ public static LinePath convertSliderPath(final SliderPath sliderPath) {
* @return The converted {@link SliderPath}.
*/
public static SliderPath convertSliderPath(final Slider slider) {
var startPosition = slider.getPosition();
var gameplayStackOffset = slider.getGameplayStackOffset();

var calculatedPath = slider.getPath().getCalculatedPath();
var cumulativeLength = slider.getPath().getCumulativeLength();

var path = new SliderPath(calculatedPath.size());
var tmpPoint = new PointF();

float realWidthScale = (float) Constants.MAP_ACTUAL_WIDTH / Constants.MAP_WIDTH;
float realHeightScale = (float) Constants.MAP_ACTUAL_HEIGHT / Constants.MAP_HEIGHT;

for (var i = 0; i < calculatedPath.size(); i++) {

var p = calculatedPath.get(i);
tmpPoint.set(startPosition.x + p.x, startPosition.y + p.y);

// The path is already flipped when the library applies the Hard Rock mod, so we don't need to do it here.
Utils.trackToRealCoords(tmpPoint);
path.setPoint(i, tmpPoint.x + gameplayStackOffset.x, tmpPoint.y + gameplayStackOffset.y);
path.setPoint(i, p.x * realWidthScale, p.y * realHeightScale);

if (i < cumulativeLength.size()) {
path.setLength(i, cumulativeLength.get(i).floatValue());
Expand Down
Loading
Loading