Skip to content

Commit 5594b9e

Browse files
committed
Merge branch 'develop'
2 parents f3d9090 + 6f9db61 commit 5594b9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1455
-791
lines changed

android/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.rolandoislas.drcsimclient"
4-
android:versionCode="3"
5-
android:versionName="1.2" >
4+
android:versionCode="8"
5+
android:versionName="2.0" >
66

77
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" />
88

android/src/com/rolandoislas/drcsimclient/android/audio/AudioDevice.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public void write(byte[] data) {
3838

3939
@Override
4040
public void write(byte[] data, int offset, int length) {
41-
audioTrack.write(data, offset, length);
41+
try {
42+
audioTrack.write(data, offset, length);
43+
}
44+
catch (IllegalStateException ignore) {}
4245
}
4346
}

build.gradle

+1-14
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,19 @@ allprojects {
1515
apply plugin: "eclipse"
1616
apply plugin: "idea"
1717

18-
version = '1.2'
18+
version = '2.0'
1919
ext {
2020
appName = "drc-sim-client"
2121
gdxVersion = '1.9.4'
2222
roboVMVersion = '2.2.0'
23-
box2DLightsVersion = '1.4'
24-
ashleyVersion = '1.7.0'
25-
aiVersion = '1.8.0'
2623
guavaVersion = '19.0'
27-
gsonVersion = '2.8.0'
28-
beamApiVersion = '3.0.3-SNAPSHOT'
29-
beamInteractiveVersion = '1.5.1-SNAPSHOT'
3024
}
3125

3226
repositories {
3327
mavenLocal()
3428
mavenCentral()
3529
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
3630
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
37-
maven {
38-
name = "beam"
39-
url = "https://maven.beam.pro/content/repositories/snapshots"
40-
}
4131
}
4232
}
4333

@@ -52,8 +42,6 @@ project(":desktop") {
5242
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
5343
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
5444
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
55-
compile "pro.beam:api:$beamApiVersion"
56-
compile "pro.beam:interactive:$beamInteractiveVersion"
5745
}
5846
}
5947

@@ -104,7 +92,6 @@ project(":core") {
10492
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
10593
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
10694
compile "com.google.guava:guava:$guavaVersion"
107-
compile "com.google.code.gson:gson:$gsonVersion"
10895
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
10996
}
11097
}

core/src/com/rolandoislas/drcsimclient/Client.java

+30-13
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import com.rolandoislas.drcsimclient.control.Control;
99
import com.rolandoislas.drcsimclient.data.ArgumentParser;
1010
import com.rolandoislas.drcsimclient.data.Constants;
11+
import com.rolandoislas.drcsimclient.graphics.TextUtil;
1112
import com.rolandoislas.drcsimclient.net.Sockets;
1213
import com.rolandoislas.drcsimclient.stage.Stage;
13-
import com.rolandoislas.drcsimclient.stage.StageConnect;
1414
import com.rolandoislas.drcsimclient.stage.StageLoad;
1515
import com.rolandoislas.drcsimclient.util.logging.Logger;
1616

@@ -25,18 +25,22 @@ public Client(Control[] controls, Audio audio, ArgumentParser argumentParser) {
2525
Client.controls = controls;
2626
Client.audio = audio;
2727
Client.args = argumentParser;
28-
Logger.info("Starting %1$s version %2$s", Constants.NAME, Constants.VERSION);
28+
Logger.info("Starting %s version %s", Constants.NAME, Constants.VERSION);
2929
}
3030

3131
public Client(Control[] controls, Audio audio) {
3232
this(controls, audio, new ArgumentParser());
3333
}
3434

35-
@Override
35+
public static Stage getStage() {
36+
return stage;
37+
}
38+
39+
@Override
3640
public void create () {
3741
sockets = new Sockets();
3842
stage = new Stage();
39-
setStage(new StageLoad());
43+
setStage(new StageLoad(true));
4044
}
4145

4246
@Override
@@ -57,23 +61,38 @@ public void dispose () {
5761
@Override
5862
public void pause() {
5963
super.pause();
60-
if (Gdx.app.getType() == Application.ApplicationType.Android)
61-
setStage(new StageConnect());
64+
if (Gdx.app.getType() == Application.ApplicationType.Android) {
65+
setStage(new StageLoad(false));
66+
TextUtil.dispose();
67+
}
6268
}
6369

6470
@Override
6571
public void resume() {
6672
super.resume();
73+
if (Gdx.app.getType() == Application.ApplicationType.Android)
74+
create();
6775
}
6876

6977
public static void setStage(Stage stage) {
70-
Logger.debug("Setting stage to %1$s", stage.getClass().getSimpleName());
71-
Client.stage.dispose();
78+
Logger.debug("Setting stage to %s", stage.getClass().getSimpleName());
79+
try {
80+
Client.stage.dispose();
81+
}
82+
catch (IllegalArgumentException e) {
83+
Logger.exception(e);
84+
}
7285
Client.stage = stage;
7386
Gdx.input.setInputProcessor(stage);
87+
Gdx.input.setCatchBackKey(true);
7488
}
7589

76-
public static boolean connect(String ip, boolean setStageOnFailure) {
90+
/**
91+
* Attempts to connect to a server at a given IP.
92+
* @param ip ip or hostname
93+
* @return empty string or error message
94+
*/
95+
public static String connect(String ip) {
7796
sockets.dispose();
7897
sockets.setIp(ip);
7998
try {
@@ -82,11 +101,9 @@ public static boolean connect(String ip, boolean setStageOnFailure) {
82101
Logger.info("Failed to connect to host \"%1$s\"", ip);
83102
Logger.info(e.getMessage());
84103
Logger.exception(e);
85-
if (setStageOnFailure)
86-
setStage(new StageConnect(e.getMessage()));
87-
return false;
104+
return e.getMessage();
88105
}
89-
return true;
106+
return "";
90107
}
91108

92109
@Override

core/src/com/rolandoislas/drcsimclient/audio/AudioThread.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ public void run() {
3333
}
3434
} catch (NetUtil.DisconnectedException e) {
3535
Logger.exception(e);
36-
running = false;
36+
Logger.info("Audio disconnected attempting to reconnect");
37+
try {
38+
Thread.sleep(5000);
39+
} catch (InterruptedException e1) {
40+
Logger.exception(e);
41+
}
42+
netUtil.resetTimeout();
43+
sockets.reconnectAudio();
3744
}
3845
}
3946
}
@@ -42,8 +49,4 @@ public void dispose() {
4249
running = false;
4350
audioUtil.dispose();
4451
}
45-
46-
public void resetTimeout() {
47-
netUtil.resetTimeout();
48-
}
4952
}
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,134 @@
11
package com.rolandoislas.drcsimclient.config;
22

3+
import com.badlogic.gdx.Preferences;
4+
import com.rolandoislas.drcsimclient.util.PreferencesUtil;
5+
6+
import java.util.Map;
7+
38
/**
49
* Created by Rolando on 2/7/2017.
510
*/
6-
public class Config {
7-
public static final String BUTTON_A = "BUTTON_A";
8-
public static final String BUTTON_B = "BUTTON_B";
9-
public static final String BUTTON_X = "BUTTON_X";
10-
public static final String BUTTON_Y = "BUTTON_Y";
11-
public static final String BUTTON_UP = "BUTTON_UP";
12-
public static final String BUTTON_DOWN = "BUTTON_DOWN";
13-
public static final String BUTTON_LEFT = "BUTTON_LEFT";
14-
public static final String BUTTON_RIGHT = "BUTTON_RIGHT";
15-
public static final String BUTTON_L = "BUTTON_L";
16-
public static final String BUTTON_R = "BUTTON_R";
17-
public static final String BUTTON_ZL = "BUTTON_ZL";
18-
public static final String BUTTON_ZR = "BUTTON_ZR";
19-
public static final String BUTTON_L3 = "BUTTON_L3";
20-
public static final String BUTTON_R3 = "BUTTON_R3";
21-
public static final String BUTTON_MINUS = "BUTTON_MINUS";
22-
public static final String BUTTON_PLUS = "BUTTON_PLUS";
23-
public static final String BUTTON_HOME = "BUTTON_HOME";
24-
public static final String JOYSTICK_LEFT_X = "JOYSTICK_LEFT_X";
25-
public static final String JOYSTICK_LEFT_Y = "JOYSTICK_LEFT_Y";
26-
public static final String JOYSTICK_RIGHT_X = "JOYSTICK_RIGHT_X";
27-
public static final String JOYSTICK_RIGHT_Y = "JOYSTICK_RIGHT_Y";
28-
public static final String MIC_BLOW = "MIC_BLOW";
29-
public int buttonA;
30-
public int buttonB;
31-
public int buttonX;
32-
public int buttonY;
33-
public int buttonUp;
34-
public int buttonDown;
35-
public int buttonLeft;
36-
public int buttonRight;
37-
public int buttonL;
38-
public int buttonR;
39-
public int buttonZL;
40-
public int buttonZR;
41-
public int buttonL3;
42-
public int buttonR3;
43-
public int buttonMinus;
44-
public int buttonPlus;
45-
public int buttonHome;
46-
public int micBlow;
47-
48-
public void set(String item, int input) {}
49-
50-
public void load() {}
51-
52-
public String get(String key) {
53-
return "";
11+
public class Config implements Preferences {
12+
private final Preferences config;
13+
private static final int CONFIG_VERSION = 2;
14+
15+
public Config(String configName) {
16+
config = PreferencesUtil.get(configName);
17+
// Clear configs if there has been a version change that would cause compatibility issues.
18+
if (getInteger("CONFIG_VERSION", 0) != CONFIG_VERSION) {
19+
config.clear();
20+
config.putInteger("CONFIG_VERSION", CONFIG_VERSION);
21+
config.flush();
22+
}
23+
}
24+
25+
public void load() {
26+
throw new RuntimeException("Not implemented");
27+
}
28+
29+
// Config wrapper
30+
@Override
31+
public Preferences putBoolean(String key, boolean val) {
32+
return config.putBoolean(key, val);
33+
}
34+
35+
@Override
36+
public Preferences putInteger(String key, int val) {
37+
return config.putInteger(key, val);
38+
}
39+
40+
@Override
41+
public Preferences putLong(String key, long val) {
42+
return config.putLong(key, val);
43+
}
44+
45+
@Override
46+
public Preferences putFloat(String key, float val) {
47+
return config.putFloat(key, val);
48+
}
49+
50+
@Override
51+
public Preferences putString(String key, String val) {
52+
return config.putString(key, val);
53+
}
54+
55+
@Override
56+
public Preferences put(Map<String, ?> vals) {
57+
return config.put(vals);
58+
}
59+
60+
@Override
61+
public boolean getBoolean(String key) {
62+
return config.getBoolean(key);
63+
}
64+
65+
@Override
66+
public int getInteger(String key) {
67+
return config.getInteger(key);
68+
}
69+
70+
@Override
71+
public long getLong(String key) {
72+
return config.getLong(key);
73+
}
74+
75+
@Override
76+
public float getFloat(String key) {
77+
return config.getFloat(key);
78+
}
79+
80+
@Override
81+
public String getString(String key) {
82+
return config.getString(key);
83+
}
84+
85+
@Override
86+
public boolean getBoolean(String key, boolean defValue) {
87+
return config.getBoolean(key, defValue);
88+
}
89+
90+
@Override
91+
public int getInteger(String key, int defValue) {
92+
return config.getInteger(key, defValue);
93+
}
94+
95+
@Override
96+
public long getLong(String key, long defValue) {
97+
return config.getLong(key, defValue);
98+
}
99+
100+
@Override
101+
public float getFloat(String key, float defValue) {
102+
return config.getFloat(key, defValue);
103+
}
104+
105+
@Override
106+
public String getString(String key, String defValue) {
107+
return config.getString(key, defValue);
108+
}
109+
110+
@Override
111+
public Map<String, ?> get() {
112+
return config.get();
113+
}
114+
115+
@Override
116+
public boolean contains(String key) {
117+
return config.contains(key);
118+
}
119+
120+
@Override
121+
public void clear() {
122+
config.clear();
123+
}
124+
125+
@Override
126+
public void remove(String key) {
127+
config.remove(key);
128+
}
129+
130+
@Override
131+
public void flush() {
132+
config.flush();
54133
}
55134
}

0 commit comments

Comments
 (0)