Skip to content

Commit

Permalink
Code cleanup and bugfixes per crash/ARN reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
forteri76 committed May 29, 2014
1 parent efc60e5 commit cf6e805
Show file tree
Hide file tree
Showing 15 changed files with 941 additions and 991 deletions.
4 changes: 2 additions & 2 deletions 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="org.jfedor.frozenbubble"
android:versionCode="31"
android:versionName="2.7">
android:versionCode="32"
android:versionName="2.8">

<supports-screens
android:smallScreens="true"
Expand Down
40 changes: 20 additions & 20 deletions src/com/efortin/frozenbubble/ModPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import com.peculiargames.andmodplug.PlayerThread;

public class ModPlayer {
private MODResourcePlayer resplayer = null;
private MODResourcePlayer resPlayer = null;

public ModPlayer(Context context,
int songId,
Expand All @@ -72,9 +72,9 @@ public ModPlayer(Context context,
*/
public void destroyMusicPlayer() {
synchronized(this) {
if (resplayer != null) {
resplayer.StopAndClose();
resplayer = null;
if (resPlayer != null) {
resPlayer.stopAndClose();
resPlayer = null;
}
}
}
Expand All @@ -87,13 +87,13 @@ public void destroyMusicPlayer() {
* playing.
*/
public void loadNewSong(int songId, boolean startPlaying) {
if (resplayer != null) {
if (resPlayer != null) {
// Pause the current song.
resplayer.PausePlay();
resPlayer.pausePlay(true);
// Load the current MOD into the player.
resplayer.LoadMODResource(songId, true);
resPlayer.loadModuleResource(songId, true);
if (startPlaying)
resplayer.UnPausePlay();
resPlayer.unPausePlay();
}
}

Expand All @@ -110,34 +110,34 @@ private void newMusicPlayer(Context context,
boolean musicOn,
boolean startPaused) {
// Create a new music player.
resplayer = new MODResourcePlayer(context);
// Load the mod file.
resplayer.LoadMODResource(songId, false);
resPlayer = new MODResourcePlayer(context);
// Load the MOD file.
resPlayer.loadModuleResource(songId, false);
// Loop the song forever.
resplayer.setLoopCount(PlayerThread.LOOP_SONG_FOREVER);
resPlayer.setLoopCount(PlayerThread.LOOP_SONG_FOREVER);
// Turn the music on or off.
setMusicOn(musicOn);
// Start the music thread.
resplayer.startPaused(startPaused);
resplayer.start();
resPlayer.startPaused(startPaused);
resPlayer.start();
}

public void pausePlay() {
if (resplayer != null)
resplayer.PausePlay();
if (resPlayer != null)
resPlayer.pausePlay(false);
}

public void setMusicOn(boolean musicOn) {
if (musicOn) {
resplayer.setVolume(255);
resPlayer.setVolume(255);
}
else {
resplayer.setVolume(0);
resPlayer.setVolume(0);
}
}

public void unPausePlay() {
if (resplayer != null)
resplayer.UnPausePlay();
if (resPlayer != null)
resPlayer.unPausePlay();
}
}
30 changes: 19 additions & 11 deletions src/com/efortin/frozenbubble/NetworkGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.jfedor.frozenbubble.FrozenBubble;
import org.jfedor.frozenbubble.FrozenGame;
import org.jfedor.frozenbubble.GameView.NetGameInterface;
import org.jfedor.frozenbubble.LevelManager;

import android.content.Context;
import android.content.SharedPreferences;
Expand Down Expand Up @@ -286,8 +287,8 @@ public void copyFromFieldData(GameFieldData fieldData) {
this.nextBubbleColor = fieldData.nextBubbleColor;
this.attackBarBubbles = fieldData.attackBarBubbles;

for (int x = 0; x < 8; x++) {
for (int y = 0; y < 13; y++) {
for (int x = 0; x < LevelManager.NUM_COLS; x++) {
for (int y = 0; y < LevelManager.NUM_ROWS; y++) {
this.gameField[x][y] = fieldData.gameField[x][y];
}
}
Expand All @@ -314,8 +315,8 @@ public void copyFromBuffer(byte[] buffer, int startIndex) {
shortBytes[1] = buffer[startIndex++];
this.attackBarBubbles = toShort(shortBytes);

for (int x = 0; x < 8; x++) {
for (int y = 0; y < 13; y++) {
for (int x = 0; x < LevelManager.NUM_COLS; x++) {
for (int y = 0; y < LevelManager.NUM_ROWS; y++) {
this.gameField[x][y] = buffer[startIndex++];
}
}
Expand All @@ -342,8 +343,8 @@ public void copyToBuffer(byte[] buffer, int startIndex) {
buffer[startIndex++] = shortBytes[0];
buffer[startIndex++] = shortBytes[1];

for (int x = 0; x < 8; x++) {
for (int y = 0; y < 13; y++) {
for (int x = 0; x < LevelManager.NUM_COLS; x++) {
for (int y = 0; y < LevelManager.NUM_ROWS; y++) {
buffer[startIndex++] = this.gameField[x][y];
}
}
Expand Down Expand Up @@ -996,8 +997,8 @@ private void getGameFieldData(GameFieldData gameData) {
gameData.attackBarBubbles = (short) gameRef.getAttackBarBubbles();

BubbleSprite[][] bubbleGrid = gameRef.getGrid();
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 13; j++) {
for (int i = 0; i < LevelManager.NUM_COLS; i++) {
for (int j = 0; j < LevelManager.NUM_ROWS; j++) {
if (bubbleGrid[i][j] != null) {
gameData.gameField[i][j] = (byte) bubbleGrid[i][j].getColor();
}
Expand Down Expand Up @@ -1258,12 +1259,12 @@ public void newGame() {
session = new MulticastManager(myContext, MCAST_BYTE_ADDR, PORT);
}
session.setMulticastListener(this);
} catch(UnknownHostException uhe) {
} catch (UnknownHostException uhe) {
if (session != null) {
session.cleanUp();
}
session = null;
} catch(IOException ioe) {
} catch (IOException ioe) {
if (session != null) {
session.cleanUp();
}
Expand All @@ -1272,7 +1273,14 @@ public void newGame() {
/*
* Start the network manager thread.
*/
start();
try {
start();
} catch (IllegalThreadStateException itse) {
/*
* The thread was already started.
*/
itse.printStackTrace();
}
}
else {
/*
Expand Down
39 changes: 19 additions & 20 deletions src/com/peculiargames/andmodplug/MODResourcePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@
* <br><code>// get player instance (in topmost activity, etc.)
* <br>mrp = MODResourcePlayer();
* <br>// load MOD/XM data into player
* <br>mrp.LoadMODResource(R.raw.coolsong);
* <br>mrp.loadModuleResource(R.raw.coolsong);
* <br>mrp.start(); // start thread (playing song)</code>
* <br><b>Then when changing songs (new game level or transition to
* another sub-activity, etc.):</b>
* <br><code>mrp.PausePlay();
* <br>mrp.LoadMODResource(R.raw.newcoolsong);
* <br>mrp.UnPausePlay();
* <br><code>mrp.pausePlay();
* <br>mrp.loadModuleResource(R.raw.newcoolsong);
* <br>mrp.unPausePlay();
* <br>// repeat...</code>
* @version 1.0
* @author P.A. Casey (crow) Peculiar-Games.com
* @author Eric Fortin
*
*/
public class MODResourcePlayer extends PlayerThread {
Expand All @@ -95,8 +96,7 @@ public class MODResourcePlayer extends PlayerThread {
* extensions.
* <p>The <code>context</code> argument is the application context
* which allows MODResourcePlayer to load resources directly.
* @param context - Application context that is creating this
* instance.
* @param context - Application context creating this instance.
*/
public MODResourcePlayer(Context context) {
// Get super class (PlayerThread) with default rate.
Expand All @@ -112,27 +112,27 @@ public MODResourcePlayer(Context context) {
* <br>Developers using Eclipse as an IDE should note that it allows
* the .xm file extension but may be fussy about other tracker format
* extensions.
* <p>The <code>modresource</code> argument is the resource id for the
* <p>The <code>modResource</code> argument is the resource id for the
* MOD/XM song file, e.g. R.raw.coolsong
* @param modresource - Android resource id for a MOD/XM/etc. (tracker
* @param modResource - Android resource ID for a MOD/XM/etc. (tracker
* format) song file.
* @param gc - if <code>true</code>, perform garbage collection prior
* to loading the file.
*/
public boolean LoadMODResource(int modresource, boolean gc) {
public boolean loadModuleResource(int modResource, boolean gc) {
byte[] modData = null;
int currfilesize = 0;
InputStream mModfileInStream;

/*
* Unload any mod file we have currently loaded.
* Unload any MOD file we have currently loaded.
*/
UnLoadMod();
unLoadMod();

/*
* Get an input stream for the MOD file resource.
*/
mModfileInStream = mContext.getResources().openRawResource(modresource);
mModfileInStream = mContext.getResources().openRawResource(modResource);
try {
currfilesize = mModfileInStream.available();
} catch (IOException e) {
Expand Down Expand Up @@ -172,19 +172,18 @@ public boolean LoadMODResource(int modresource, boolean gc) {
/*
* Load the song into the player.
*/
LoadMODData(modData);
loadModuleData(modData);
return true;
}

/**
* Stop playing the song, close down the player and
* <code>join()</code> the player thread.
* <p>Typically called in the application's (Activity's)
* <code>onPause()</code> method.
* <p>Typically called in the application's main activity
* <code>onDestroy()</code> method.
*/
public void StopAndClose() {
PausePlay();
StopThread();
public void stopAndClose() {
stopThread();
/*
* Now close and join() the MOD player thread.
*/
Expand All @@ -199,7 +198,7 @@ public void StopAndClose() {
*/
}
}
CloseLIBMODPLUG();
InvalidatePlayer();
closeLibModPlug();
invalidatePlayer();
}
}
Loading

0 comments on commit cf6e805

Please sign in to comment.