From 502d177c02d8c53a3eb87c04f4bc7d341d2d4bad Mon Sep 17 00:00:00 2001 From: forteri76 Date: Tue, 13 May 2014 12:29:26 +0000 Subject: [PATCH] Elmiinated spurious code and performed cleanup regarding network game synchronization. --- AndroidManifest.xml | 4 +- src/org/jfedor/frozenbubble/FrozenGame.java | 65 ++++----------------- src/org/jfedor/frozenbubble/GameView.java | 31 ++++------ 3 files changed, 24 insertions(+), 76 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 396eaae..52ee362 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="26" + android:versionName="2.2"> jumping; BubbleSprite[][] bubblePlay; - byte[][] newGrid; BmpWrap gameWon, gameLost; @@ -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); @@ -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. @@ -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 - true 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 - true to play the compression sound. @@ -911,7 +894,6 @@ else if (fixedBubbles == 7) { /* * Perform game synchronization tasks. */ - synchronizeNetworkGame(); synchronizeBubbleManager(); /* @@ -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 @@ -1298,7 +1272,14 @@ else if (result == gameEnum.LOST) } } - private void setGrid() { + /** + * Perform bubble grid and compressor synchronization. + *

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(); @@ -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) { @@ -1435,24 +1408,6 @@ public void synchronizeBubbleManager() { } } - /** - * If this is a network game, process bubble grid and compressor - * synchronization tasks. - *

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 play() function, all - * synchronization tasks will be automatically serviced eventually. - *

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); diff --git a/src/org/jfedor/frozenbubble/GameView.java b/src/org/jfedor/frozenbubble/GameView.java index 9b97757..1618d91 100644 --- a/src/org/jfedor/frozenbubble/GameView.java +++ b/src/org/jfedor/frozenbubble/GameView.java @@ -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); } /* @@ -2849,8 +2849,7 @@ 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) { @@ -2858,41 +2857,35 @@ private void setPlayerGameField(GameFieldData newField) { 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,