Skip to content

Commit

Permalink
Fixed the accelerometer control, moved the constants from AliteStartM…
Browse files Browse the repository at this point in the history
…anager to AliteConfig and removed the necessity to update the code of AliteIntro when building the different versions.
  • Loading branch information
CmdrStardust committed Mar 5, 2016
1 parent 1bbd002 commit 9657f68
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ tags
bin/
gen/R.java.d
main.*.de.phbouillon.android.games.alite.obb
/local.properties
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.phbouillon.android.games.alite"
android:versionCode="2195"
android:versionName="1.4.4"
android:versionCode="2197"
android:versionName="1.4.6"
android:installLocation="auto" xmlns:tools="http://schemas.android.com/tools">

<uses-sdk
Expand Down
35 changes: 21 additions & 14 deletions ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Alite v. 1.4.4 by Philipp Bouillon and Duane McDonnell
Alite v. 1.4.6 by Philipp Bouillon and Duane McDonnell

About
-----
Expand All @@ -19,6 +19,14 @@ exploration directly to you - wherever you are.
Version History
---------------

Version 1.4.6 Really fixes the accelerometer control. It's now independent of
the orientation. Also changed the radar color of cargo
canisters. [03/03/2016]

Version 1.4.5 Tries to fix a problem with the accelerometer control: If you
are playing lying down, the pitch will change in mid-movement.
[02/28/2016]

Version 1.4.4 Repairs the broken 1.4.3, which contained a typo and thus
rendered the version useless. [02/12/2016]

Expand All @@ -33,9 +41,9 @@ Version 1.4.2 Comes with an improved "Medium Speed" Docking Computer. The
[02/07/2016]

Version 1.4.1 Bugfixes: Corrupt image replaced, Planet Info in WitchSpace
enabled, Asteroid course randomized, tutorials now work if the
legal status is not clean. Medium Speed Docking Computer added.
[01/23/2016]
enabled, Asteroid course randomized, tutorials now work if
the legal status is not clean. Medium Speed Docking Computer
added. [01/23/2016]

Version 1.4.0 Introduces the TimeWarp feature, implemented by Steven Phillips.
The TimeWarp lets you pass those regions in space where the torus
Expand Down Expand Up @@ -98,10 +106,10 @@ If you import Alite into ADT and connect your device, you can install it
without the need to download any additional libraries. However, there are a
couple of things you need to know:

In the class "de.phbouillon.android.games.alite.AliteStartManager", you find
In the class "de.phbouillon.android.games.alite.AliteConfig", you find
the constant HAS_EXTENSION_APK, which is set to true. This means that all
assets of Alite are stored in an "obb" file, which needs to be installed in
the directory "<phone>/Android/obb/de.phbouillon.android.games.alite/main.2180.de.phbouillon.android.games.alite.obb".
the directory "<phone>/Android/obb/de.phbouillon.android.games.alite/main.2192.de.phbouillon.android.games.alite.obb".

Now you have two options:

Expand Down Expand Up @@ -131,9 +139,9 @@ a command prompt or shell in that directory and type:
java -jar jobb.jar -d Resources -o main.<VERSION>.de.phbouillon.android.games.alite.obb -pn de.phbouillon.android.games.alite -pv <VERSION>

and make sure that <VERSION> _exactly!_ matches the version number you
specified in the AliteStartManager, see EXTENSION_FILE_VERSION.
specified in the AliteConfig, see EXTENSION_FILE_VERSION.

Once built set EXTENSION_FILE_LENGTH in AliteStartManager to the size of your
Once built set EXTENSION_FILE_LENGTH in AliteConfig to the size of your
new obb file in bytes and rebuild & install Alite.

Why is that so complicated?! I wish I knew :). The thing is that the jobb tool
Expand All @@ -153,17 +161,16 @@ article here: http://developer.android.com/google/play/expansion-files.html

If you only want to enhance Alite and test it on your device, or you don't
want to bother handling OBBs, set the "HAS_EXTENSION_APK" flag to false in
the AliteStartManager class.
the AliteConfig class.
This tells Alite that all files have to be loaded from the assets directory.
So, if you set the flag to "false", copy all files from the Resources/assets
directory to the assets/directory.
directory to the assets/ directory.
Next, copy the files from the Resources/intro directory to the res/raw
directory ("raw" has to be created).
Now, one more thing to do:
In "AliteIntro", you'll find the method "determineIntroId(int quality)" and
several commented lines below it: uncomment those and comment the final return.
In line 179, replace the "introId = -1;" with
"introId = R.raw.alite_intro_b1920;".
In "AliteConfig", you'll find the constants ALITE_INTRO_XXX. Replace their
-1 value with the "R.raw.alite_intro_xxx" value you'll find in the comments
of the AliteConfig file.

Done. When you now deploy Alite, you don't have to keep an OBB file on your
phone and you'll instantly see changes to resources you made. But deployment
Expand Down
21 changes: 20 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,26 @@
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->

<target name="release"
depends="-set-release-mode, -package, -post-package, -release-sign, -post-build"
description="Builds the application in release mode.">
</target>

<target name="-config" depends="clean">
<property name="config-target-path" value="${source.dir}/de/phbouillon/android/games/alite"/>

<copy file="config/AliteConfig.java" todir="${config-target-path}" overwrite="true" encoding="utf-8">
<filterset>
<filter token="CONFIG.HAS_EXTENSION_APK" value="false"/>
</filterset>
</copy>
</target>

<target name="release-all" depends="-config">
</target>

<!-- version-tag: custom -->
<import file="${sdk.dir}/tools/ant/build.xml" />

</project>
Binary file removed libs/android-support-v4.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
target=android-19
40 changes: 27 additions & 13 deletions src/de/phbouillon/android/framework/impl/AccelerometerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@
import android.hardware.SensorManager;
import android.view.OrientationEventListener;
import android.view.WindowManager;
import de.phbouillon.android.framework.math.Vector3f;
import de.phbouillon.android.games.alite.Settings;

public class AccelerometerHandler implements SensorEventListener {
public static boolean needsCalibration = true;

private float [] accelValues = new float[3];
private float [] adjustedValues = new float[3];
private Vector3f accelerationVector = new Vector3f(0, 0, 0);
private Vector3f accelerationMean = new Vector3f(0, 0, 0);
private Vector3f accelerationCalibration = new Vector3f(0, 0, 0);
private Vector3f rollVector = new Vector3f(0, 0, 0);
private Vector3f pitchVector = new Vector3f(0, 0, 0);
private Vector3f upVector = new Vector3f(0, 1, 0);
private Vector3f tempVector = new Vector3f(0, 0, 0);

private final AndroidGame game;
private int defaultOrientation;
private boolean reversedLandscape = false;
Expand Down Expand Up @@ -124,20 +135,23 @@ public void adjustAccelOrientation(float [] eventValues) {

@Override
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
for (int i = 0; i < 3; i++) {
accelValues[i] = event.values[i];
}
break;
accelerationVector.x = event.values[0];
accelerationVector.y = event.values[1];
accelerationVector.z = event.values[2];
accelerationVector.normalize();

accelerationVector.copy(accelerationMean);
if (needsCalibration) {
needsCalibration = false;
accelerationVector.copy(accelerationCalibration);
upVector.copy(rollVector);
upVector.cross(accelerationCalibration, pitchVector);
}

float roll = (float) Math.atan2(accelValues[0], accelValues[2]);
float pitch = (float) Math.atan2(accelValues[1], accelValues[2]);

accelValues[2] = -roll;
accelValues[1] = -pitch;
accelValues[0] = 0;

accelerationMean.sub(accelerationCalibration, tempVector);
accelValues[0] = 0; // Yaw
accelValues[1] = tempVector.dot(rollVector); // Roll
accelValues[2] = tempVector.dot(pitchVector); // Pitch
adjustAccelOrientation(accelValues);
}

Expand Down
6 changes: 3 additions & 3 deletions src/de/phbouillon/android/framework/impl/AndroidAudio.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import de.phbouillon.android.framework.Audio;
import de.phbouillon.android.framework.Music;
import de.phbouillon.android.framework.Sound;
import de.phbouillon.android.games.alite.AliteConfig;
import de.phbouillon.android.games.alite.AliteLog;
import de.phbouillon.android.games.alite.AliteStartManager;

public class AndroidAudio implements Audio {
public static final int MAXIMUM_NUMBER_OF_CONCURRENT_SAMPLES = 20;
Expand All @@ -47,7 +47,7 @@ public AndroidAudio(Activity activity, AndroidFileIO fileIO) {

@Override
public Music newMusic(String fileName, Sound.SoundType soundType) {
if (AliteStartManager.HAS_EXTENSION_APK) {
if (AliteConfig.HAS_EXTENSION_APK) {
try {
return new AndroidMusic(fileIO, fileName, soundType);
} catch (IOException e) {
Expand All @@ -70,7 +70,7 @@ public Music newMusic(String fileName, Sound.SoundType soundType) {
@Override
public Sound newSound(String fileName, Sound.SoundType soundType) {
try {
int soundId = AliteStartManager.HAS_EXTENSION_APK ?
int soundId = AliteConfig.HAS_EXTENSION_APK ?
soundPool.load(fileIO.getPrivatePath(fileName), 0) :
soundPool.load(fileIO.getFileDescriptor(fileName), 0);
return new AndroidSound(soundPool, soundId, soundType);
Expand Down
10 changes: 5 additions & 5 deletions src/de/phbouillon/android/framework/impl/AndroidFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import android.content.res.AssetManager;
import android.os.Environment;
import de.phbouillon.android.framework.FileIO;
import de.phbouillon.android.games.alite.AliteStartManager;
import de.phbouillon.android.games.alite.AliteConfig;
import de.phbouillon.android.games.alite.io.ObbExpansionsManager;

public class AndroidFileIO implements FileIO {
Expand Down Expand Up @@ -318,7 +318,7 @@ public void unzip(File zipFile, File targetDirectory) throws IOException {

@Override
public boolean existsPrivateFile(String fileName) throws IOException {
if (AliteStartManager.HAS_EXTENSION_APK) {
if (AliteConfig.HAS_EXTENSION_APK) {
return new File(ObbExpansionsManager.getInstance().getMainRoot() + "assets/" + fileName).exists();
}
try {
Expand All @@ -332,22 +332,22 @@ public boolean existsPrivateFile(String fileName) throws IOException {

@Override
public InputStream readPrivateFile(String fileName) throws IOException {
if (AliteStartManager.HAS_EXTENSION_APK) {
if (AliteConfig.HAS_EXTENSION_APK) {
return new FileInputStream(getPrivatePath(fileName));
}
return assets.open(fileName);
}

public AssetFileDescriptor getFileDescriptor(String fileName) throws IOException {
if (AliteStartManager.HAS_EXTENSION_APK) {
if (AliteConfig.HAS_EXTENSION_APK) {
throw new IOException("Cannot access extension assets via AssetDescriptor. Use private path instead.");
}
return assets.openFd(fileName);
}

@Override
public String getPrivatePath(String fileName) throws IOException {
if (AliteStartManager.HAS_EXTENSION_APK) {
if (AliteConfig.HAS_EXTENSION_APK) {
String path;
if (ObbExpansionsManager.getInstance() == null) {
throw new IOException("Obb not loaded. Please try all-in-one solution from http://alite.mobi.");
Expand Down
5 changes: 5 additions & 0 deletions src/de/phbouillon/android/framework/impl/VideoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,9 @@ public boolean canSeekBackward() {
public boolean canSeekForward() {
return mCanSeekForward;
}

@Override
public int getAudioSessionId() {
return 1;
}
}
7 changes: 4 additions & 3 deletions src/de/phbouillon/android/games/alite/Alite.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import de.phbouillon.android.games.alite.screens.opengl.sprites.AliteFont;

public class Alite extends AndroidGame {
public static final String VERSION_STRING = "1.4.4 " + (AliteStartManager.HAS_EXTENSION_APK ? "OBB" : "SFI");
public static final String VERSION_STRING = AliteConfig.VERSION_STRING + " " + (AliteConfig.HAS_EXTENSION_APK ? "OBB" : "SFI");
public static final String LOG_IS_INITIALIZED = "logIsInitialized";

private Player player;
Expand Down Expand Up @@ -448,8 +448,9 @@ public void afterSurfaceCreated() {
Assets.italicFont = new GLText();
Assets.boldItalicFont = new GLText();
Assets.titleFont = new GLText();
Assets.smallFont = new GLText();
if (AliteStartManager.HAS_EXTENSION_APK) {
Assets.smallFont = new GLText();

if (AliteConfig.HAS_EXTENSION_APK) {
Assets.regularFont.load(ObbExpansionsManager.getInstance().getMainRoot() + "assets/robotor.ttf", (int) (40.0f * scaleFactor), 40, 2, 2);
Assets.boldFont.load(ObbExpansionsManager.getInstance().getMainRoot() + "assets/robotob.ttf", (int) (40.0f * scaleFactor), 40, 2, 2);
Assets.italicFont.load(ObbExpansionsManager.getInstance().getMainRoot() + "assets/robotoi.ttf", (int) (40.0f * scaleFactor), 40, 2, 2);
Expand Down
14 changes: 14 additions & 0 deletions src/de/phbouillon/android/games/alite/AliteConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.phbouillon.android.games.alite;

public class AliteConfig {
public static final boolean HAS_EXTENSION_APK = false;
public static final int EXTENSION_FILE_VERSION = 2192;
public static final long EXTENSION_FILE_LENGTH = 427312705l;
public static final String VERSION_STRING = "1.4.6";
public static final int ALITE_INTRO_B1920 = -1; //R.raw.alite_intro_b1920;
public static final int ALITE_INTRO_B1280 = -1; //R.raw.alite_intro_b1280;
public static final int ALITE_INTRO_B640 = -1; //R.raw.alite_intro_b640;
public static final int ALITE_INTRO_B320 = -1; //R.raw.alite_intro_b320;
public static final int ALITE_INTRO_288 = -1; //R.raw.alite_intro_288;
public static final int ALITE_INTRO_B240 = -1; //R.raw.alite_intro_b240;
}
41 changes: 20 additions & 21 deletions src/de/phbouillon/android/games/alite/AliteIntro.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,22 @@ private FileDescriptor getFileDescriptor(String file) throws IOException {
}

private int determineIntroId(int quality) {
// switch (quality) {
// case 0: AliteLog.d("Video Playback", "Using video resolution 1920x1080");
// return R.raw.alite_intro_b1920;
// case 1: AliteLog.d("Video Playback", "Using video resolution 1280x720");
// return R.raw.alite_intro_b1280;
// case 2: AliteLog.d("Video Playback", "Using video resolution 640x360");
// return R.raw.alite_intro_b640;
// case 3: AliteLog.d("Video Playback", "Using video resolution 320x180");
// return R.raw.alite_intro_b320;
// case 4: AliteLog.d("Video Playback", "Failsafe mode 1: 288");
// return R.raw.alite_intro_288;
// case 5: AliteLog.d("Video Playback", "Failsafe mode 2: 240");
// return R.raw.alite_intro_b240;
// default: AliteLog.d("Video Playback", "No mode found. Giving up :(.");
// return -1;
// }
return -1;
switch (quality) {
case 0: AliteLog.d("Video Playback", "Using video resolution 1920x1080");
return AliteConfig.ALITE_INTRO_B1920;
case 1: AliteLog.d("Video Playback", "Using video resolution 1280x720");
return AliteConfig.ALITE_INTRO_B1280;
case 2: AliteLog.d("Video Playback", "Using video resolution 640x360");
return AliteConfig.ALITE_INTRO_B640;
case 3: AliteLog.d("Video Playback", "Using video resolution 320x180");
return AliteConfig.ALITE_INTRO_B320;
case 4: AliteLog.d("Video Playback", "Failsafe mode 1: 288");
return AliteConfig.ALITE_INTRO_288;
case 5: AliteLog.d("Video Playback", "Failsafe mode 2: 240");
return AliteConfig.ALITE_INTRO_B240;
default: AliteLog.d("Video Playback", "No mode found. Giving up :(.");
return -1;
}
}

private String determineIntroFilename(int quality) {
Expand Down Expand Up @@ -164,7 +163,7 @@ public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
if (videoView == null) {
initializeVideoView();
}
if (AliteStartManager.HAS_EXTENSION_APK) {
if (AliteConfig.HAS_EXTENSION_APK) {
playVideoFromOBB();
} else {
playVideoFromRawFolder();
Expand All @@ -178,7 +177,7 @@ private void playVideoFromRawFolder() {
if (Settings.introVideoQuality == 255) {
cyclingThroughVideoQualities = 0;
AliteLog.d("Video Playback", "Using video resolution 1920x1080");
introId = -1; //R.raw.alite_intro_b1920;
introId = AliteConfig.ALITE_INTRO_B1920;
} else {
introId = determineIntroId(Settings.introVideoQuality);
}
Expand Down Expand Up @@ -260,7 +259,7 @@ public void onCompletion(final MediaPlayer mp) {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
AliteLog.d("cyclingThroughVideoQualities [1]", "cyclingThroughVideoQualities = " + cyclingThroughVideoQualities);
if (AliteStartManager.HAS_EXTENSION_APK) {
if (AliteConfig.HAS_EXTENSION_APK) {
if (errorHandlerObb(mp)) {
return true;
}
Expand Down Expand Up @@ -340,7 +339,7 @@ private boolean errorHandlerObb(final MediaPlayer mp) {
// Ignore
}
}
if (AliteStartManager.HAS_EXTENSION_APK) {
if (AliteConfig.HAS_EXTENSION_APK) {
videoViewFileInputStream = new FileInputStream(getAbsolutePath(introFilename));
AliteLog.d("Intro path", "Intro path: " + getAbsolutePath(introFilename));
videoView.setVideoFD(videoViewFileInputStream.getFD());
Expand Down
Loading

0 comments on commit 9657f68

Please sign in to comment.