Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandoislas committed Jun 18, 2017
2 parents f3d9090 + 6f9db61 commit 5594b9e
Show file tree
Hide file tree
Showing 43 changed files with 1,455 additions and 791 deletions.
4 changes: 2 additions & 2 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rolandoislas.drcsimclient"
android:versionCode="3"
android:versionName="1.2" >
android:versionCode="8"
android:versionName="2.0" >

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public void write(byte[] data) {

@Override
public void write(byte[] data, int offset, int length) {
audioTrack.write(data, offset, length);
try {
audioTrack.write(data, offset, length);
}
catch (IllegalStateException ignore) {}
}
}
15 changes: 1 addition & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,19 @@ allprojects {
apply plugin: "eclipse"
apply plugin: "idea"

version = '1.2'
version = '2.0'
ext {
appName = "drc-sim-client"
gdxVersion = '1.9.4'
roboVMVersion = '2.2.0'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
guavaVersion = '19.0'
gsonVersion = '2.8.0'
beamApiVersion = '3.0.3-SNAPSHOT'
beamInteractiveVersion = '1.5.1-SNAPSHOT'
}

repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
maven {
name = "beam"
url = "https://maven.beam.pro/content/repositories/snapshots"
}
}
}

Expand All @@ -52,8 +42,6 @@ project(":desktop") {
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "pro.beam:api:$beamApiVersion"
compile "pro.beam:interactive:$beamInteractiveVersion"
}
}

Expand Down Expand Up @@ -104,7 +92,6 @@ project(":core") {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
compile "com.google.guava:guava:$guavaVersion"
compile "com.google.code.gson:gson:$gsonVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
}
}
Expand Down
43 changes: 30 additions & 13 deletions core/src/com/rolandoislas/drcsimclient/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.rolandoislas.drcsimclient.control.Control;
import com.rolandoislas.drcsimclient.data.ArgumentParser;
import com.rolandoislas.drcsimclient.data.Constants;
import com.rolandoislas.drcsimclient.graphics.TextUtil;
import com.rolandoislas.drcsimclient.net.Sockets;
import com.rolandoislas.drcsimclient.stage.Stage;
import com.rolandoislas.drcsimclient.stage.StageConnect;
import com.rolandoislas.drcsimclient.stage.StageLoad;
import com.rolandoislas.drcsimclient.util.logging.Logger;

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

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

@Override
public static Stage getStage() {
return stage;
}

@Override
public void create () {
sockets = new Sockets();
stage = new Stage();
setStage(new StageLoad());
setStage(new StageLoad(true));
}

@Override
Expand All @@ -57,23 +61,38 @@ public void dispose () {
@Override
public void pause() {
super.pause();
if (Gdx.app.getType() == Application.ApplicationType.Android)
setStage(new StageConnect());
if (Gdx.app.getType() == Application.ApplicationType.Android) {
setStage(new StageLoad(false));
TextUtil.dispose();
}
}

@Override
public void resume() {
super.resume();
if (Gdx.app.getType() == Application.ApplicationType.Android)
create();
}

public static void setStage(Stage stage) {
Logger.debug("Setting stage to %1$s", stage.getClass().getSimpleName());
Client.stage.dispose();
Logger.debug("Setting stage to %s", stage.getClass().getSimpleName());
try {
Client.stage.dispose();
}
catch (IllegalArgumentException e) {
Logger.exception(e);
}
Client.stage = stage;
Gdx.input.setInputProcessor(stage);
Gdx.input.setCatchBackKey(true);
}

public static boolean connect(String ip, boolean setStageOnFailure) {
/**
* Attempts to connect to a server at a given IP.
* @param ip ip or hostname
* @return empty string or error message
*/
public static String connect(String ip) {
sockets.dispose();
sockets.setIp(ip);
try {
Expand All @@ -82,11 +101,9 @@ public static boolean connect(String ip, boolean setStageOnFailure) {
Logger.info("Failed to connect to host \"%1$s\"", ip);
Logger.info(e.getMessage());
Logger.exception(e);
if (setStageOnFailure)
setStage(new StageConnect(e.getMessage()));
return false;
return e.getMessage();
}
return true;
return "";
}

@Override
Expand Down
13 changes: 8 additions & 5 deletions core/src/com/rolandoislas/drcsimclient/audio/AudioThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ public void run() {
}
} catch (NetUtil.DisconnectedException e) {
Logger.exception(e);
running = false;
Logger.info("Audio disconnected attempting to reconnect");
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
Logger.exception(e);
}
netUtil.resetTimeout();
sockets.reconnectAudio();
}
}
}
Expand All @@ -42,8 +49,4 @@ public void dispose() {
running = false;
audioUtil.dispose();
}

public void resetTimeout() {
netUtil.resetTimeout();
}
}
175 changes: 127 additions & 48 deletions core/src/com/rolandoislas/drcsimclient/config/Config.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,134 @@
package com.rolandoislas.drcsimclient.config;

import com.badlogic.gdx.Preferences;
import com.rolandoislas.drcsimclient.util.PreferencesUtil;

import java.util.Map;

/**
* Created by Rolando on 2/7/2017.
*/
public class Config {
public static final String BUTTON_A = "BUTTON_A";
public static final String BUTTON_B = "BUTTON_B";
public static final String BUTTON_X = "BUTTON_X";
public static final String BUTTON_Y = "BUTTON_Y";
public static final String BUTTON_UP = "BUTTON_UP";
public static final String BUTTON_DOWN = "BUTTON_DOWN";
public static final String BUTTON_LEFT = "BUTTON_LEFT";
public static final String BUTTON_RIGHT = "BUTTON_RIGHT";
public static final String BUTTON_L = "BUTTON_L";
public static final String BUTTON_R = "BUTTON_R";
public static final String BUTTON_ZL = "BUTTON_ZL";
public static final String BUTTON_ZR = "BUTTON_ZR";
public static final String BUTTON_L3 = "BUTTON_L3";
public static final String BUTTON_R3 = "BUTTON_R3";
public static final String BUTTON_MINUS = "BUTTON_MINUS";
public static final String BUTTON_PLUS = "BUTTON_PLUS";
public static final String BUTTON_HOME = "BUTTON_HOME";
public static final String JOYSTICK_LEFT_X = "JOYSTICK_LEFT_X";
public static final String JOYSTICK_LEFT_Y = "JOYSTICK_LEFT_Y";
public static final String JOYSTICK_RIGHT_X = "JOYSTICK_RIGHT_X";
public static final String JOYSTICK_RIGHT_Y = "JOYSTICK_RIGHT_Y";
public static final String MIC_BLOW = "MIC_BLOW";
public int buttonA;
public int buttonB;
public int buttonX;
public int buttonY;
public int buttonUp;
public int buttonDown;
public int buttonLeft;
public int buttonRight;
public int buttonL;
public int buttonR;
public int buttonZL;
public int buttonZR;
public int buttonL3;
public int buttonR3;
public int buttonMinus;
public int buttonPlus;
public int buttonHome;
public int micBlow;

public void set(String item, int input) {}

public void load() {}

public String get(String key) {
return "";
public class Config implements Preferences {
private final Preferences config;
private static final int CONFIG_VERSION = 2;

public Config(String configName) {
config = PreferencesUtil.get(configName);
// Clear configs if there has been a version change that would cause compatibility issues.
if (getInteger("CONFIG_VERSION", 0) != CONFIG_VERSION) {
config.clear();
config.putInteger("CONFIG_VERSION", CONFIG_VERSION);
config.flush();
}
}

public void load() {
throw new RuntimeException("Not implemented");
}

// Config wrapper
@Override
public Preferences putBoolean(String key, boolean val) {
return config.putBoolean(key, val);
}

@Override
public Preferences putInteger(String key, int val) {
return config.putInteger(key, val);
}

@Override
public Preferences putLong(String key, long val) {
return config.putLong(key, val);
}

@Override
public Preferences putFloat(String key, float val) {
return config.putFloat(key, val);
}

@Override
public Preferences putString(String key, String val) {
return config.putString(key, val);
}

@Override
public Preferences put(Map<String, ?> vals) {
return config.put(vals);
}

@Override
public boolean getBoolean(String key) {
return config.getBoolean(key);
}

@Override
public int getInteger(String key) {
return config.getInteger(key);
}

@Override
public long getLong(String key) {
return config.getLong(key);
}

@Override
public float getFloat(String key) {
return config.getFloat(key);
}

@Override
public String getString(String key) {
return config.getString(key);
}

@Override
public boolean getBoolean(String key, boolean defValue) {
return config.getBoolean(key, defValue);
}

@Override
public int getInteger(String key, int defValue) {
return config.getInteger(key, defValue);
}

@Override
public long getLong(String key, long defValue) {
return config.getLong(key, defValue);
}

@Override
public float getFloat(String key, float defValue) {
return config.getFloat(key, defValue);
}

@Override
public String getString(String key, String defValue) {
return config.getString(key, defValue);
}

@Override
public Map<String, ?> get() {
return config.get();
}

@Override
public boolean contains(String key) {
return config.contains(key);
}

@Override
public void clear() {
config.clear();
}

@Override
public void remove(String key) {
config.remove(key);
}

@Override
public void flush() {
config.flush();
}
}
Loading

0 comments on commit 5594b9e

Please sign in to comment.