Skip to content

Commit df6b03c

Browse files
committed
Merge tag 'v151.1' into be
2 parents ae8083f + c93f3ff commit df6b03c

File tree

14 files changed

+110
-30
lines changed

14 files changed

+110
-30
lines changed

arc-core/src/arc/Application.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,21 @@ default long getNativeHeap(){
7474
return 0;
7575
}
7676

77-
@Nullable
78-
String getClipboardText();
77+
/** @return the main graphics thread, upon which all ApplicationListener methods are called. May return null if not initialized. */
78+
default @Nullable Thread getMainThread(){
79+
return null;
80+
}
81+
82+
/**
83+
* @return whether the currently executing thread is the main thread.
84+
* If the main thread is not initialized, returns true by default. This is used for error checking purposes.
85+
* */
86+
default boolean isOnMainThread(){
87+
Thread thread = getMainThread();
88+
return thread == null || Thread.currentThread() == thread;
89+
}
90+
91+
@Nullable String getClipboardText();
7992

8093
void setClipboardText(String text);
8194

arc-core/src/arc/audio/Audio.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,18 @@ public void setLooping(int soundId, boolean looping){
132132

133133
public void setPitch(int soundId, float pitch){
134134
if(!initialized) return;
135-
idPitch(soundId, pitch);
135+
if(!Float.isInfinite(pitch) && !Float.isNaN(pitch)) idPitch(soundId, pitch);
136136
}
137137

138138
public void setVolume(int soundId, float volume){
139139
if(!initialized) return;
140-
idVolume(soundId, volume);
140+
if(!Float.isInfinite(volume) && !Float.isNaN(volume)) idVolume(soundId, volume);
141141
}
142142

143143
public void set(int soundId, float pan, float volume){
144144
if(!initialized) return;
145-
idVolume(soundId, volume);
146-
idPan(soundId, pan);
145+
if(!Float.isInfinite(volume) && !Float.isNaN(volume)) idVolume(soundId, volume);
146+
if(!Float.isInfinite(pan) && !Float.isNaN(pan)) idPan(soundId, pan);
147147
}
148148

149149
public void fadeFilterParam(int voice, int filter, int attribute, float value, float timeSec){

arc-core/src/arc/audio/Sound.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public void load(Fi file){
6767
public int play(float volume, float pitch, float pan, boolean loop, boolean checkFrame){
6868
if(handle == 0 || (checkFrame && framePlayed == Core.graphics.getFrameId()) || bus == null || !Core.audio.initialized) return -1;
6969
framePlayed = Core.graphics.getFrameId();
70+
71+
if(Float.isInfinite(volume) || Float.isNaN(volume)) volume = 0f;
72+
if(Float.isInfinite(pan) || Float.isNaN(pan)) pan = 0f;
73+
if(Float.isInfinite(pitch) || Float.isNaN(pitch)) pitch = 1f;
74+
7075
return sourcePlayBus(handle, bus.handle, volume, Mathf.clamp(pitch * Core.audio.globalPitch, 0.0001f, 10f), Mathf.clamp(pan, -1f, 1f), loop);
7176
}
7277

arc-core/src/arc/mock/MockApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import arc.struct.*;
55

66
public class MockApplication implements Application{
7+
78
@Override
89
public Seq<ApplicationListener> getListeners(){
910
return new Seq<>();

arc-core/src/arc/util/Strings.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package arc.util;
22

33
import arc.graphics.*;
4+
import arc.math.*;
45
import arc.struct.*;
56

67
import java.io.*;
@@ -576,9 +577,18 @@ public static float parseFloat(String s, float defaultValue){
576577
}
577578

578579
public static String autoFixed(float value, int max){
579-
int precision = Math.abs((int)(value + 0.0001f) - value) <= 0.0001f ? 0 :
580-
Math.abs((int)(value * 10 + 0.0001f) - value * 10) <= 0.0001f ? 1 : 2;
581-
return fixed(value, Math.min(precision, max));
580+
581+
//truncate extra digits past the max
582+
value = (float)Mathf.floor(value * Mathf.pow(10, max) + 0.001f) / Mathf.pow(10, max);
583+
584+
int precision =
585+
Math.abs(Mathf.floor(value) - value) < 0.0001f ? 0 :
586+
Math.abs(Mathf.floor(value * 10) - value * 10) < 0.0001f ? 1 :
587+
Math.abs(Mathf.floor(value * 100) - value * 100) < 0.0001f ? 2 :
588+
Math.abs(Mathf.floor(value * 1000) - value * 1000) < 0.0001f ? 3 :
589+
4;
590+
591+
return fixed(value, Math.min(max, precision));
582592
}
583593

584594
public static String fixed(float d, int decimalPlaces){

arc-core/test/StringsTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@
66

77
public class StringsTest{
88

9+
@Test
10+
public void testFixed(){
11+
Object[] values = {
12+
3, 1.327f, "1.327",
13+
2, 1.327f, "1.32",
14+
1, 1.327f, "1.3",
15+
0, 1.327f, "1",
16+
3, 1.3005f, "1.3",
17+
2, 0.0001f, "0",
18+
4, 0.0001f, "0.0001",
19+
3, 0.0001f, "0",
20+
2, 2.435f, "2.43",
21+
2, 2.99f, "2.99",
22+
2, 2.99999f, "3",
23+
2, 0f, "0"
24+
};
25+
26+
for(int i = 0; i < values.length; i += 3){
27+
assertEquals(values[i + 2], Strings.autoFixed((Float)values[i + 1], (Integer)values[i]));
28+
}
29+
}
30+
931
@Test
1032
public void testLongParse(){
1133
Seq.with("0", "+0", "-0", "235235", "99424", "1234", "1", "-24242", "170589", "-289157", "4246", "19284", "-672396", "-42412042040945", "1592835012852095")

backends/backend-android/src/arc/backend/android/AndroidApplication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class AndroidApplication extends Activity implements Application{
4141
protected ClipboardManager clipboard;
4242
protected boolean useImmersiveMode = false;
4343
protected boolean hideStatusBar = false;
44+
protected @Nullable Thread mainThread;
4445

4546
static{
4647
ArcNativesLoader.load();
@@ -168,6 +169,11 @@ protected void hideStatusBar(boolean hide){
168169
getWindow().getDecorView().setSystemUiVisibility(0x1);
169170
}
170171

172+
@Override
173+
public Thread getMainThread(){
174+
return mainThread;
175+
}
176+
171177
@Override
172178
public void getDnsServers(Seq<InetSocketAddress> out){
173179
if(getVersion() < 21) return; //needs API level 21

backends/backend-android/src/arc/backend/android/AndroidGraphics.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public void onSurfaceChanged(GL10 gl, int width, int height){
217217
updatePpi();
218218
gl.glViewport(0, 0, this.width, this.height);
219219
if(!created){
220+
app.mainThread = Thread.currentThread();
220221
for(ApplicationListener list : app.getListeners()){
221222
list.init();
222223
}

backends/backend-headless/src/arc/backend/headless/HeadlessApplication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ void mainLoop(){
103103
}
104104
}
105105

106+
@Override
107+
public Thread getMainThread(){
108+
return mainLoopThread;
109+
}
110+
106111
@Override
107112
public ApplicationType getType(){
108113
return ApplicationType.headless;

backends/backend-robovm/src/arc/backend/robovm/IOSApplication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class IOSApplication implements Application{
2121
IOSApplicationConfiguration config;
2222
IOSGraphics graphics;
2323
IOSInput input;
24+
Thread mainThread;
2425
@Nullable IOSDevice device;
2526
float displayScaleFactor;
2627

@@ -151,6 +152,11 @@ final void willTerminate(UIApplication uiApp){
151152
Gl.finish();
152153
}
153154

155+
@Override
156+
public Thread getMainThread(){
157+
return mainThread;
158+
}
159+
154160
@Override
155161
public ApplicationType getType(){
156162
return ApplicationType.iOS;

0 commit comments

Comments
 (0)