Skip to content

Commit ef44368

Browse files
committed
Merge branch 'develop'
2 parents d19b3da + c4f9033 commit ef44368

File tree

29 files changed

+780
-112
lines changed

29 files changed

+780
-112
lines changed

.travis.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
language: android
2+
3+
jdk:
4+
- oraclejdk8
5+
6+
android:
7+
components:
8+
- tools
9+
- build-tools-25.0.2
10+
- android-25
11+
12+
install: true
13+
14+
before_script:
15+
- chmod +x gradlew
16+
17+
script:
18+
- ./gradlew android:build
19+
- ./gradlew desktop:build
20+
21+
before_cache:
22+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
23+
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
24+
cache:
25+
directories:
26+
- $HOME/.gradle/caches/
27+
- $HOME/.gradle/wrapper/
28+
- $HOME/.android/build-cache

android/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ android {
2222
minSdkVersion 9
2323
targetSdkVersion 25
2424
}
25+
lintOptions {
26+
abortOnError false
27+
}
2528
}
2629

2730

android/src/com/rolandoislas/drcsimclient/android/AndroidLauncher.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.rolandoislas.drcsimclient.control.Control;
99
import com.rolandoislas.drcsimclient.control.ControlController;
1010
import com.rolandoislas.drcsimclient.control.ControlTouch;
11+
import com.rolandoislas.drcsimclient.data.ArgumentParser;
1112

1213
public class AndroidLauncher extends AndroidApplication {
1314
@Override
@@ -17,6 +18,7 @@ protected void onCreate (Bundle savedInstanceState) {
1718
config.useImmersiveMode = true;
1819
config.useWakelock = true;
1920
Control[] controls = new Control[] {new ControlTouch(), new ControlController()};
20-
initialize(new Client(controls, new Audio()), config);
21+
ArgumentParser args = new ArgumentParser(new String[]{"-f"});
22+
initialize(new Client(controls, new Audio(), args), config);
2123
}
2224
}

build.gradle

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:2.2.0'
9+
classpath 'com.android.tools.build:gradle:2.2.2'
1010
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.2.0'
1111
}
1212
}
@@ -25,13 +25,19 @@ allprojects {
2525
aiVersion = '1.8.0'
2626
guavaVersion = '19.0'
2727
gsonVersion = '2.8.0'
28+
beamApiVersion = '3.0.3-SNAPSHOT'
29+
beamInteractiveVersion = '1.5.1-SNAPSHOT'
2830
}
2931

3032
repositories {
3133
mavenLocal()
3234
mavenCentral()
3335
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
3436
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
37+
maven {
38+
name = "beam"
39+
url = "https://maven.beam.pro/content/repositories/snapshots"
40+
}
3541
}
3642
}
3743

@@ -46,6 +52,8 @@ project(":desktop") {
4652
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
4753
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
4854
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
55+
compile "pro.beam:api:$beamApiVersion"
56+
compile "pro.beam:interactive:$beamInteractiveVersion"
4957
}
5058
}
5159

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@
66
import com.badlogic.gdx.graphics.GL20;
77
import com.rolandoislas.drcsimclient.audio.Audio;
88
import com.rolandoislas.drcsimclient.control.Control;
9+
import com.rolandoislas.drcsimclient.data.ArgumentParser;
10+
import com.rolandoislas.drcsimclient.data.Constants;
911
import com.rolandoislas.drcsimclient.net.Sockets;
1012
import com.rolandoislas.drcsimclient.stage.Stage;
1113
import com.rolandoislas.drcsimclient.stage.StageConnect;
12-
import com.rolandoislas.drcsimclient.stage.StageControl;
1314
import com.rolandoislas.drcsimclient.stage.StageLoad;
1415
import com.rolandoislas.drcsimclient.util.logging.Logger;
1516

1617
public class Client extends ApplicationAdapter {
18+
public static ArgumentParser args;
1719
public static Audio audio;
1820
private static Stage stage;
1921
public static Sockets sockets;
2022
public static Control[] controls;
2123

22-
public Client(Control[] controls, Audio audio) {
24+
public Client(Control[] controls, Audio audio, ArgumentParser argumentParser) {
2325
Client.controls = controls;
2426
Client.audio = audio;
27+
Client.args = argumentParser;
28+
Logger.info("Starting %1$s version %2$s", Constants.NAME, Constants.VERSION);
29+
}
30+
31+
public Client(Control[] controls, Audio audio) {
32+
this(controls, audio, new ArgumentParser());
2533
}
2634

2735
@Override
@@ -65,13 +73,17 @@ public static void setStage(Stage stage) {
6573
Gdx.input.setInputProcessor(stage);
6674
}
6775

68-
public static boolean connect(String ip) {
76+
public static boolean connect(String ip, boolean setStageOnFailure) {
6977
sockets.dispose();
7078
sockets.setIp(ip);
7179
try {
7280
sockets.connect();
7381
} catch (Exception e) {
74-
setStage(new StageConnect(e.getMessage()));
82+
Logger.info("Failed to connect to host \"%1$s\"", ip);
83+
Logger.info(e.getMessage());
84+
Logger.exception(e);
85+
if (setStageOnFailure)
86+
setStage(new StageConnect(e.getMessage()));
7587
return false;
7688
}
7789
return true;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.rolandoislas.drcsimclient.audio;
22

33
import com.rolandoislas.drcsimclient.net.NetUtil;
4-
5-
import java.io.IOException;
4+
import com.rolandoislas.drcsimclient.util.logging.Logger;
65

76
import static com.rolandoislas.drcsimclient.Client.sockets;
87

@@ -13,8 +12,9 @@ public class AudioThread extends Thread {
1312
private final AudioUtil audioUtil;
1413
private boolean running = true;
1514

16-
public AudioThread(AudioUtil audioUtil) {
17-
this.audioUtil = audioUtil;
15+
public AudioThread() {
16+
this.audioUtil = new AudioUtil();
17+
this.setName("Network Thread: Audio");
1818
}
1919

2020
@Override
@@ -23,14 +23,21 @@ public void run() {
2323
try {
2424
byte[] packet = NetUtil.recv(sockets.socketAud, "audio");
2525
audioUtil.addData(packet);
26-
} catch (IOException e) {
27-
if (e.getMessage().contains("Disconnected"))
28-
dispose();
26+
} catch (NetUtil.ReadTimeoutException ignore) {
27+
try {
28+
Thread.sleep(10);
29+
} catch (InterruptedException e) {
30+
Logger.exception(e);
31+
}
32+
} catch (NetUtil.DisconnectedException e) {
33+
Logger.exception(e);
34+
running = false;
2935
}
3036
}
3137
}
3238

3339
public void dispose() {
3440
running = false;
41+
audioUtil.dispose();
3542
}
3643
}

core/src/com/rolandoislas/drcsimclient/control/ControlKeyboard.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,20 @@ public void update() {
4747
buttonbits |= Constants.BUTTON_ZL;
4848
if (Gdx.input.isKeyPressed(config.buttonZR))
4949
buttonbits |= Constants.BUTTON_ZR;
50-
if (Gdx.input.isKeyPressed(config.buttonL3))
51-
buttonbits |= Constants.BUTTON_L3;
52-
if (Gdx.input.isKeyPressed(config.buttonR3))
53-
buttonbits |= Constants.BUTTON_R3;
5450
if (Gdx.input.isKeyPressed(config.buttonMinus))
5551
buttonbits |= Constants.BUTTON_MINUS;
5652
if (Gdx.input.isKeyPressed(config.buttonPlus))
5753
buttonbits |= Constants.BUTTON_PLUS;
5854
if (Gdx.input.isKeyPressed(config.buttonHome))
5955
buttonbits |= Constants.BUTTON_HOME;
6056
sockets.sendButtonInput(buttonbits);
57+
// L3R3
58+
int extraButtonBits = 0;
59+
if (Gdx.input.isKeyPressed(config.buttonL3))
60+
extraButtonBits |= Constants.BUTTON_L3;
61+
if (Gdx.input.isKeyPressed(config.buttonR3))
62+
extraButtonBits |= Constants.BUTTON_R3;
63+
sockets.sendExtraButtonInput(extraButtonBits);
6164
// Joystick
6265
// TODO get joystick input based on mouse capture
6366
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.rolandoislas.drcsimclient.data;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
/**
7+
* Created by Rolando on 2/18/2017.
8+
*/
9+
public class ArgumentParser {
10+
private final List<String> argsList;
11+
public final String ip;
12+
public final String apiBeam;
13+
public final boolean logDebug;
14+
public final boolean logExtra;
15+
public final boolean logVerbose;
16+
17+
public ArgumentParser(String[] args) {
18+
argsList = Arrays.asList(args);
19+
ip = getArgAfter("-ip");
20+
apiBeam = getArgAfter("-api-beam");
21+
logDebug = hasOption("-d", "--debug");
22+
logExtra = hasOption("-e", "--extra", "-f", "--finer");
23+
logVerbose = hasOption("-v", "--verbose");
24+
}
25+
26+
private boolean hasOption(String... options) {
27+
for (String opt : options)
28+
if (argsList.contains(opt))
29+
return true;
30+
return false;
31+
}
32+
33+
private String getArgAfter(String arg) {
34+
if (!argsList.contains(arg)
35+
|| argsList.indexOf(arg) + 1 >= argsList.size()
36+
|| argsList.get(argsList.indexOf(arg) + 1).startsWith("-"))
37+
return "";
38+
return argsList.get(argsList.indexOf(arg) + 1);
39+
}
40+
41+
public ArgumentParser() {
42+
this(new String[]{});
43+
}
44+
}

core/src/com/rolandoislas/drcsimclient/data/Constants.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
* Created by Rolando on 12/21/2016.
77
*/
88
public class Constants {
9+
// Info
10+
public static final String NAME = "DRC Sim Client";
11+
public static final String VERSION = "1.1";
912
// Ports
1013
public static final int PORT_SERVER_VID = 50000;
1114
public static final int PORT_SERVER_AUD = 50001;
1215
public static final int PORT_SERVER_CMD = 50002;
1316
// Commands
1417
public static final String COMMAND_REGISTER = "REGISTER";
1518
public static final String COMMAND_INPUT_BUTTON = "INPUT_BUTTON";
16-
public static final String COMMAND_INPUT_L3R3 = "INPUT_L3R3";
19+
public static final String COMMAND_INPUT_BUTTON_EXTRA = "INPUT_L3R3"; // TODO rename on server
1720
public static final String COMMAND_INPUT_TOUCH = "INPUT_TOUCH";
1821
public static final String COMMAND_INPUT_JOYSTICK = "INPUT_JOYSTICK";
1922
public static final String COMMAND_VIBRATE = "VIBRATE";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.rolandoislas.drcsimclient.graphics;
2+
3+
import com.rolandoislas.drcsimclient.net.NetUtil;
4+
import com.rolandoislas.drcsimclient.stage.StageConnect;
5+
import com.rolandoislas.drcsimclient.util.logging.Logger;
6+
7+
import static com.rolandoislas.drcsimclient.Client.setStage;
8+
import static com.rolandoislas.drcsimclient.Client.sockets;
9+
10+
/**
11+
* Created by rolando on 4/6/17.
12+
*/
13+
public class VideoThread extends Thread {
14+
private boolean running = true;
15+
private byte[] imageData = new byte[0];
16+
17+
public VideoThread() {
18+
this.setName("Network Thread: Video");
19+
}
20+
21+
@Override
22+
public void run() {
23+
while (running) {
24+
try {
25+
byte[] data = NetUtil.recv(sockets.socketVid, "video");
26+
synchronized (this) {
27+
imageData = data;
28+
}
29+
} catch (NetUtil.ReadTimeoutException ignore) {
30+
try {
31+
Thread.sleep(10);
32+
} catch (InterruptedException e) {
33+
Logger.exception(e);
34+
}
35+
} catch (NetUtil.DisconnectedException e) {
36+
Logger.exception(e);
37+
Logger.info("Disconnected");
38+
dispose();
39+
}
40+
}
41+
}
42+
43+
public void dispose() {
44+
running = false;
45+
}
46+
47+
public byte[] getImageData() {
48+
byte[] data;
49+
synchronized (this) {
50+
data = imageData;
51+
imageData = new byte[0];
52+
}
53+
return data;
54+
}
55+
}

core/src/com/rolandoislas/drcsimclient/net/Codec.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,20 @@ public static byte[] encodeCommand(String name, String data) {
2626
return encodedString.getBytes();
2727
}
2828

29+
/**
30+
* Parses a command packet
31+
* @param packet command packet
32+
* @return Returns a string array with the command as the first entry and extra data as the second.
33+
* The second entry will be an empty string on no extra data.
34+
* Both entries will be empty strings if the packet starts with null data.
35+
*/
2936
public static String[] decodeCommand(DatagramPacket packet) {
30-
return new String(packet.getData(), 0, packet.getLength()).split(commandDelimiter);
37+
if (packet.getData()[0] == 0x0)
38+
return new String[]{"", ""};
39+
String[] command = new String(packet.getData(), 0, packet.getLength()).split(commandDelimiter);
40+
if (command.length == 1)
41+
command = new String[]{command[0], ""};
42+
return command;
3143
}
3244

3345
public static String encodeInput(Object o) {

0 commit comments

Comments
 (0)