Skip to content

Commit

Permalink
Elmiinated spurious code and performed cleanup regarding network game…
Browse files Browse the repository at this point in the history
… synchronization.
  • Loading branch information
forteri76 committed May 13, 2014
1 parent 69c2f1f commit 502d177
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 76 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="25"
android:versionName="2.1">
android:versionCode="26"
android:versionName="2.2">

<supports-screens
android:smallScreens="true"
Expand Down
65 changes: 10 additions & 55 deletions src/org/jfedor/frozenbubble/FrozenGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ public class FrozenGame extends GameScreen {
double launchBubblePosition;

PenguinSprite penguin;

byte newSteps;
Compressor compressor;

ImageSprite nextBubble;
Expand All @@ -119,7 +117,6 @@ public class FrozenGame extends GameScreen {
Vector<Sprite> jumping;

BubbleSprite[][] bubblePlay;
byte[][] newGrid;

BmpWrap gameWon, gameLost;

Expand Down Expand Up @@ -224,7 +221,6 @@ public FrozenGame(BmpWrap background_arg,
penguin = new PenguinSprite(getPenguinRect(player), penguins_arg, random);
this.addSprite(penguin);

newSteps = -1;
compressor = new Compressor(compressorHead_arg, compressor_arg);
hurrySprite = new ImageSprite(new Rect(203, 265, 203 + 240, 265 + 90),
hurry_arg);
Expand All @@ -240,7 +236,6 @@ public FrozenGame(BmpWrap background_arg,

bubblePlay = new BubbleSprite[8][13];
bubbleManager = new BubbleManager(bubbles);
newGrid = null;

/*
* Load the current level to the bubble play grid.
Expand Down Expand Up @@ -539,18 +534,6 @@ private void initFrozenify() {
frozenify = true;
}

/**
* Lower the bubbles in play and drop the compressor the required
* number of steps.
* @param playSound - <code>true</code> to play the compression sound.
*/
private void lowerCompressorSteps(boolean playSound) {
for (int index = 0; index < newSteps; index++) {
lowerCompressor(playSound);
}
newSteps = -1;
}

/**
* Lower the bubbles in play and drop the compressor a step.
* @param playSound - <code>true</code> to play the compression sound.
Expand Down Expand Up @@ -911,7 +894,6 @@ else if (fixedBubbles == 7) {
/*
* Perform game synchronization tasks.
*/
synchronizeNetworkGame();
synchronizeBubbleManager();

/*
Expand Down Expand Up @@ -1264,14 +1246,6 @@ public void saveState(Bundle map) {
}
}

/**
* Lower the compressor to the specified number of steps.
* @param newSteps - the number of compressor steps to lower to.
*/
public void setCompressorSteps(byte newSteps) {
this.newSteps = newSteps;
}

/**
* Set the game result associated with this player.
* @param result - GAME_WON if this player won the game, GAME_LOST if
Expand All @@ -1298,7 +1272,14 @@ else if (result == gameEnum.LOST)
}
}

private void setGrid() {
/**
* Perform bubble grid and compressor synchronization.
* <p>To prevent the appearance of glitches, the game field should not
* be synchronized while bubbles are in motion.
* @param newGrid - the new bubble grid to apply to the game field.
* @param newSteps - the number of compressor steps to lower to.
*/
public void setGrid(byte[][] newGrid, byte newSteps) {
if (newGrid != null) {
compressor.init();
falling.clear();
Expand All @@ -1320,18 +1301,10 @@ private void setGrid() {
}
}
}
newGrid = null;
}
}

public void setGrid(byte[][] newGrid) {
this.newGrid = new byte[8][13];
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 13; j++) {
this.newGrid[i][j] = newGrid[i][j];
}
for (int index = 0; index < newSteps; index++) {
lowerCompressor(false);
}
synchronizeNetworkGame();
}

public void setLaunchBubbleColors(int current, int next, int newNext) {
Expand Down Expand Up @@ -1435,24 +1408,6 @@ public void synchronizeBubbleManager() {
}
}

/**
* If this is a network game, process bubble grid and compressor
* synchronization tasks.
* <p>To prevent the appearance of glitches, do not synchronize the
* game field while a launched bubble is in motion. Since this method
* is called in every loop of the <code>play()</code> function, all
* synchronization tasks will be automatically serviced eventually.
* <p>Note that during game initialization, there is never a launch
* bubble in motion, so a call to this method at that time will always
* immediately perform any necessary synchronization tasks.
*/
private void synchronizeNetworkGame() {
if ((movingBubble == null) && (networkManager != null)) {
setGrid();
lowerCompressorSteps(newSteps == 1);
}
}

public void updatePenguinState(double dx) {
if (dx < 0) {
penguin.updateState(PenguinSprite.STATE_TURN_LEFT);
Expand Down
31 changes: 12 additions & 19 deletions src/org/jfedor/frozenbubble/GameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@ else if (newAction.playerID == VirtualInput.PLAYER2) {
* Process a compressor lower request.
*/
if (newAction.compress) {
playerRef.mGameRef.setCompressorSteps((byte)1);
playerRef.mGameRef.lowerCompressor(true);
}

/*
Expand Down Expand Up @@ -2849,50 +2849,43 @@ private void setPlayerAction(PlayerAction newAction) {
}

/**
* Set the game field for a remote player - as in a person playing
* via a client device over a network.
* Set the remote player client game field.
* @param newGameField - the object containing the remote field data.
*/
private void setPlayerGameField(GameFieldData newField) {
if (newField == null) {
return;
}

VirtualInput playerRef;
FrozenGame gameRef;

if (newField.playerID == VirtualInput.PLAYER1) {
playerRef = mPlayer1;
gameRef = mPlayer1.mGameRef;
}
else if (newField.playerID == VirtualInput.PLAYER2) {
playerRef = mPlayer2;
gameRef = mPlayer2.mGameRef;
}
else {
return;
}

/*
* Lower the compressor and bubbles in play to the required number
* of compressor steps.
*/
playerRef.mGameRef.setCompressorSteps(newField.compressorSteps);

/*
* Set the bubble grid.
* Set the bubble grid, and lower the compressor and bubbles in play
* to the required number of compressor steps.
*/
playerRef.mGameRef.setGrid(newField.gameField);
gameRef.setGrid(newField.gameField, newField.compressorSteps);

/*
* Set the launcher bubble colors.
*/
playerRef.mGameRef.setLaunchBubbleColors(newField.launchBubbleColor,
newField.nextBubbleColor,
playerRef.mGameRef.getNewNextColor());
gameRef.setLaunchBubbleColors(newField.launchBubbleColor,
newField.nextBubbleColor,
gameRef.getNewNextColor());

/*
* Set the current value of the attack bar.
*/
playerRef.mGameRef.malusBar.setAttackBubbles(newField.attackBarBubbles,
null);
gameRef.malusBar.setAttackBubbles(newField.attackBarBubbles, null);
}

public void surfaceChanged(SurfaceHolder holder, int format, int width,
Expand Down

0 comments on commit 502d177

Please sign in to comment.