Skip to content

Commit 216d747

Browse files
committed
Adapt effects to buffer system changes
1 parent 5a1da4a commit 216d747

4 files changed

Lines changed: 65 additions & 30 deletions

File tree

src/com/osudroid/ui/v2/mainmenu/RadialVisualizer.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.osudroid.ui.v2.mainmenu
33
import com.edlplan.framework.easing.Easing
44
import com.osudroid.RythimManager
55
import com.reco1l.andengine.Anchor
6+
import com.reco1l.andengine.buffered.BufferSharingMode
67
import com.reco1l.andengine.component.UIComponent
78
import com.reco1l.andengine.shape.UIBox
89
import com.reco1l.andengine.theme.Colors
@@ -57,7 +58,7 @@ class RadialVisualizer : UIComponent() {
5758
color = Colors.White
5859
anchor = Anchor.Center
5960
origin = Anchor.BottomCenter
60-
allowBufferCache = false
61+
bufferSharingMode = BufferSharingMode.Dynamic
6162
})
6263
}
6364

@@ -103,15 +104,15 @@ class RadialVisualizer : UIComponent() {
103104
override fun onDrawChildren(gl: GL10, camera: Camera) {
104105
val bars = bars
105106

106-
val maxBarHeight = visualizerRadius * 2f
107107
val baseBarHeight = visualizerRadius
108108

109109
bars.fastForEachIndexed { index, barInfo ->
110110

111111
val angle = (index.toFloat() / bars.size) * 2f * PI.toFloat()
112112

113113
barBox.width = barThickness
114-
barBox.height = baseBarHeight + maxBarHeight * barInfo.currentHeight.coerceIn(0f, 1f)
114+
barBox.height = baseBarHeight
115+
barBox.scaleY = 1f + 2f * barInfo.currentHeight.coerceIn(0f, 1f)
115116
barBox.rotation = Math.toDegrees(angle.toDouble()).toFloat()
116117

117118
barBox.onDraw(gl, camera)

src/com/osudroid/ui/v2/mainmenu/RippleVisualizer.kt

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package com.osudroid.ui.v2.mainmenu
22

33
import com.osudroid.RythimManager
44
import com.reco1l.andengine.Anchor
5+
import com.reco1l.andengine.buffered.BufferSharingMode
56
import com.reco1l.andengine.component.UIComponent
67
import com.reco1l.andengine.shape.PaintStyle
78
import com.reco1l.andengine.shape.UICircle
89
import com.reco1l.andengine.theme.Colors
9-
import com.reco1l.andengine.theme.rem
10-
import com.reco1l.toolkt.kotlin.fastForEachIndexed
10+
import com.reco1l.toolkt.kotlin.fastForEach
1111
import org.anddev.andengine.engine.camera.Camera
1212
import java.lang.ref.WeakReference
1313
import javax.microedition.khronos.opengles.GL10
@@ -32,6 +32,12 @@ class RippleVisualizer : UIComponent() {
3232

3333
private var activeRipples = mutableListOf<RippleInfo>()
3434

35+
/**
36+
* The base size of the ripple relative to the largest dimension.
37+
*/
38+
private val baseRippleSize: Float
39+
get() = max(width, height)
40+
3541

3642
init {
3743
attachChild(ripple.apply {
@@ -40,8 +46,20 @@ class RippleVisualizer : UIComponent() {
4046
origin = Anchor.Center
4147
paintStyle = PaintStyle.Outline
4248
lineWidth = rippleThickness
43-
allowBufferCache = false
49+
bufferSharingMode = BufferSharingMode.Dynamic
4450
})
51+
}
52+
53+
override fun onSizeChanged() {
54+
super.onSizeChanged()
55+
ripple.width = baseRippleSize
56+
ripple.height = baseRippleSize
57+
}
58+
59+
override fun onAttached() {
60+
super.onAttached()
61+
ripple.width = baseRippleSize
62+
ripple.height = baseRippleSize
4563

4664
RythimManager.addOnBeatChangeListener(referenceToThis) {
4765
if (RythimManager.isKiai) {
@@ -58,7 +76,7 @@ class RippleVisualizer : UIComponent() {
5876
}
5977

6078
override fun onManagedUpdate(deltaTimeSec: Float) {
61-
activeRipples.fastForEachIndexed { index, info ->
79+
activeRipples.fastForEach { info ->
6280
info.update(deltaTimeSec)
6381
}
6482
activeRipples.removeAll { it.alpha <= 0f }
@@ -67,12 +85,8 @@ class RippleVisualizer : UIComponent() {
6785
}
6886

6987
override fun onDrawChildren(gl: GL10, camera: Camera) {
70-
val baseSize = max(width, height)
71-
72-
activeRipples.fastForEachIndexed { index, info ->
73-
val size = baseSize + (baseSize / 3) * info.size
74-
ripple.width = size
75-
ripple.height = size
88+
activeRipples.fastForEach { info ->
89+
ripple.setScale(1f + info.scale)
7690
ripple.alpha = info.alpha
7791
ripple.onDraw(gl, camera)
7892
}
@@ -84,7 +98,7 @@ class RippleVisualizer : UIComponent() {
8498

8599

86100
data class RippleInfo(
87-
var size: Float,
101+
var scale: Float,
88102
var alpha: Float
89103
) {
90104

@@ -96,9 +110,9 @@ class RippleVisualizer : UIComponent() {
96110
alpha -= fadeRate * deltaTimeSec
97111

98112
// The velocity is proportional to the alpha value
99-
velocity = max(0f, alpha * (if (RythimManager.isKiai) 3f else 1.5f))
113+
velocity = max(0f, alpha * (if (RythimManager.isKiai) 1f else 0.5f))
100114

101-
size += velocity * deltaTimeSec
115+
scale += velocity * deltaTimeSec
102116
}
103117
}
104118

src/com/osudroid/ui/v2/mainmenu/TrianglesDispenser.kt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
package com.osudroid.ui.v2.mainmenu
22

33
import com.reco1l.andengine.Anchor
4+
import com.reco1l.andengine.buffered.BufferSharingMode
45
import com.reco1l.andengine.component.UIComponent
56
import com.reco1l.andengine.component.scaleCenter
67
import com.reco1l.andengine.shape.UITriangle
78
import com.reco1l.andengine.theme.Colors
89
import com.reco1l.framework.Color4
910
import com.reco1l.toolkt.kotlin.fastForEach
10-
import com.reco1l.toolkt.kotlin.fastForEachIndexed
1111
import org.anddev.andengine.engine.camera.Camera
1212
import javax.microedition.khronos.opengles.GL10
1313
import kotlin.random.Random
1414

1515
class TrianglesDispenser : UIComponent() {
1616

1717
/**
18-
* The min size of triangles relative to the dispenser size.
18+
* The minimum scale factor for triangles.
1919
*/
2020
var triangleMinSize = 0.2f
2121

2222
/**
23-
* The max size of triangles relative to the dispenser size.
23+
* The maximum scale factor for triangles.
2424
*/
2525
var triangleMaxSize = 0.4f
2626

@@ -55,20 +55,32 @@ class TrianglesDispenser : UIComponent() {
5555
val triangle = UITriangle()
5656

5757

58+
/**
59+
* The base size of the triangle shape relative to the dispenser height.
60+
*/
61+
private val triangleBaseSize: Float
62+
get() = height * 0.6f
63+
64+
5865
private var activeTriangles = mutableListOf<TriangleInfo>()
5966

6067
private var spawnTimer = 0f
6168

6269

6370
init {
6471
attachChild(triangle.apply {
65-
width = triangleMinSize
6672
color = Colors.White
6773
scaleCenter = Anchor.Center
68-
allowBufferCache = false
74+
bufferSharingMode = BufferSharingMode.Dynamic
6975
})
7076
}
7177

78+
override fun onSizeChanged() {
79+
super.onSizeChanged()
80+
triangle.width = triangleBaseSize
81+
triangle.height = triangleBaseSize
82+
}
83+
7284

7385
override fun onManagedUpdate(deltaTimeSec: Float) {
7486
// Update spawn timer
@@ -86,16 +98,14 @@ class TrianglesDispenser : UIComponent() {
8698
info.update(deltaTimeSec)
8799
}
88100

89-
// Remove triangles that went off screen (above the dispenser)
90-
activeTriangles.removeAll { it.y < -it.size }
101+
activeTriangles.removeAll { it.y < -(triangleBaseSize * it.scale) }
91102

92103
super.onManagedUpdate(deltaTimeSec)
93104
}
94105

95106
override fun onDrawChildren(gl: GL10, camera: Camera) {
96-
activeTriangles.fastForEachIndexed { index, info ->
97-
triangle.width = info.size
98-
triangle.height = info.size
107+
activeTriangles.fastForEach { info ->
108+
triangle.setScale(info.scale)
99109
triangle.y = info.y
100110
triangle.x = info.x
101111
triangle.color = info.color
@@ -110,7 +120,7 @@ class TrianglesDispenser : UIComponent() {
110120

111121

112122
private fun spawnTriangle() {
113-
val size = height * Random.nextFloat().let {
123+
val scale = Random.nextFloat().let {
114124
triangleMinSize + it * (triangleMaxSize - triangleMinSize)
115125
}
116126

@@ -120,18 +130,18 @@ class TrianglesDispenser : UIComponent() {
120130

121131
val color = colorPalette.random()
122132
val x = Random.nextFloat() * width
123-
val y = height + size
133+
val y = height + triangleBaseSize * scale
124134

125135
val rotation = if (Random.nextBoolean()) 0f else 180f
126136

127-
activeTriangles.add(TriangleInfo(x, y, size, velocity, color, rotation))
137+
activeTriangles.add(TriangleInfo(x, y, scale, velocity, color, rotation))
128138
}
129139

130140

131141
data class TriangleInfo(
132142
var x: Float,
133143
var y: Float,
134-
var size: Float,
144+
var scale: Float,
135145
var velocity: Float,
136146
var color: Color4,
137147
var rotation: Float,

src/com/reco1l/andengine/buffered/UIBufferedComponent.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ abstract class UIBufferedComponent<T : IBuffer> : UIComponent() {
4848
*/
4949
var clearInfo = ClearInfo.None
5050

51+
/**
52+
* The buffer sharing mode
53+
*/
54+
var bufferSharingMode = BufferSharingMode.Off
55+
set(value) {
56+
field = value
57+
buffer?.sharingMode = value
58+
}
59+
5160

5261
private var needsBufferUpdate = true
5362

@@ -111,6 +120,7 @@ abstract class UIBufferedComponent<T : IBuffer> : UIComponent() {
111120
}
112121

113122
val buffer = buffer
123+
buffer?.sharingMode = bufferSharingMode
114124

115125
// If the buffer is shared and its sharing mode is dynamic, we
116126
// need to update it before drawing every frame, this might be

0 commit comments

Comments
 (0)