[vlc-commits] Puzzle: fix shapes bug when changing game mode

Vianney Boyer git at videolan.org
Thu Aug 15 12:24:19 CEST 2013


vlc | branch: master | Vianney Boyer <vlcvboyer at gmail.com> | Fri Jul 26 20:02:15 2013 +0200| [c6f70c96654b89b66be6da32490096eb95903cbf] | committer: Jean-Baptiste Kempf

Puzzle: fix shapes bug when changing game mode

This fix regenerates the shapes when you change the game mode. However you'll see straight shapes.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c6f70c96654b89b66be6da32490096eb95903cbf
---

 modules/video_filter/puzzle_mgt.c |   47 +++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/modules/video_filter/puzzle_mgt.c b/modules/video_filter/puzzle_mgt.c
index b6a9862..8f2fd19 100644
--- a/modules/video_filter/puzzle_mgt.c
+++ b/modules/video_filter/puzzle_mgt.c
@@ -957,4 +957,51 @@ void puzzle_load( filter_t *p_filter, save_game_t *ps_save_game)
                 break;
             }
     }
+
+    for (uint32_t i_pce=0; i_pce < p_sys->s_allocated.i_pieces_nbr; i_pce++) {
+        /* redefine shapes */
+        uint32_t i_left_pce  = 0;
+        uint32_t i_right_pce = 6;
+        uint32_t i_top_pce   = 2;
+        uint32_t i_btm_pce   = 4;
+
+        uint32_t i_pce_pair = 0;
+        for (int32_t i_row = 0; i_row < p_sys->s_allocated.i_rows; i_row++)
+            for (int32_t i_col = 0; i_col < p_sys->s_allocated.i_cols; i_col++) {
+                if (p_sys->ps_pieces[i_pce].i_original_row == p_sys->ps_pieces[i_pce_pair].i_original_row) {
+                    if (p_sys->ps_pieces[i_pce].i_original_col == p_sys->ps_pieces[i_pce_pair].i_original_col - 1)
+                        i_right_pce = i_pce_pair;
+                    else if (p_sys->ps_pieces[i_pce].i_original_col == p_sys->ps_pieces[i_pce_pair].i_original_col + 1)
+                        i_left_pce = i_pce_pair;
+                }
+                else if (p_sys->ps_pieces[i_pce].i_original_col == p_sys->ps_pieces[i_pce_pair].i_original_col) {
+                    if (p_sys->ps_pieces[i_pce].i_original_row == p_sys->ps_pieces[i_pce_pair].i_original_row - 1)
+                        i_btm_pce = i_pce_pair;
+                    else if (p_sys->ps_pieces[i_pce].i_original_row == p_sys->ps_pieces[i_pce_pair].i_original_row + 1)
+                        i_top_pce = i_pce_pair;
+                }
+                i_pce_pair++;
+            }
+
+        if ((p_sys->ps_pieces[i_pce].i_left_shape == 0) && (p_sys->ps_pieces[i_pce].i_original_col != 0)) {
+            p_sys->ps_pieces[i_left_pce].i_right_shape = 6 + 8 + 8*(( (unsigned) vlc_mrand48()) % ( SHAPES_QTY ) ) + (vlc_mrand48() & 0x01);
+            p_sys->ps_pieces[i_pce].i_left_shape = (p_sys->ps_pieces[i_left_pce].i_right_shape - 6 ) ^ 0x01;
+        }
+
+        if ((p_sys->ps_pieces[i_pce].i_right_shape == 6) && (p_sys->ps_pieces[i_pce].i_original_col != p_sys->s_allocated.i_cols-1)) {
+            p_sys->ps_pieces[i_pce].i_right_shape = 6 + 8 + 8*(( (unsigned) vlc_mrand48()) % ( SHAPES_QTY ) ) + (vlc_mrand48() & 0x01);
+            p_sys->ps_pieces[i_right_pce].i_left_shape = (p_sys->ps_pieces[i_pce].i_right_shape - 6 ) ^ 0x01;
+        }
+
+        if ((p_sys->ps_pieces[i_pce].i_top_shape == 2) && (p_sys->ps_pieces[i_pce].i_original_row != 0)) {
+            p_sys->ps_pieces[i_top_pce].i_btm_shape = 4 + 8 + 8*(( (unsigned) vlc_mrand48()) % ( SHAPES_QTY ) ) + (vlc_mrand48() & 0x01);
+            p_sys->ps_pieces[i_pce].i_top_shape = (p_sys->ps_pieces[i_top_pce].i_btm_shape - 2 ) ^ 0x01;
+        }
+
+        if ((p_sys->ps_pieces[i_pce].i_btm_shape == 4) && (p_sys->ps_pieces[i_pce].i_original_row != p_sys->s_allocated.i_rows-1)) {
+            p_sys->ps_pieces[i_pce].i_btm_shape = 4 + 8 + 8*(( (unsigned) vlc_mrand48()) % ( SHAPES_QTY ) ) + (vlc_mrand48() & 0x01);
+            p_sys->ps_pieces[i_btm_pce].i_top_shape = (p_sys->ps_pieces[i_pce].i_btm_shape - 2 ) ^ 0x01;
+        }
+
+    }
 }



More information about the vlc-commits mailing list