1 /*****************************************************************************
2  * puzzle_mgt.h : Puzzle game filter - game management
3  *****************************************************************************
4  * Copyright (C) 2005-2009 VLC authors and VideoLAN
5  * Copyright (C) 2013      Vianney Boyer
6  * $Id: 87006a787cb70165a36659a7dfa541340813894b $
7  *
8  * Authors: Vianney Boyer <vlcvboyer -at- gmail -dot- com>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #ifndef VLC_LIB_PUZZLE_MGT_H
29 #define VLC_LIB_PUZZLE_MGT_H 1
30 
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34 #include <math.h>
35 
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
38 #include <vlc_filter.h>
39 #include <vlc_rand.h>
40 
41 #include "puzzle_bezier.h"
42 #include "puzzle_lib.h"
43 #include "puzzle_pce.h"
44 #include "puzzle_mgt.h"
45 
46 #define NO_PCE -1
47 
48 
49 /*****************************************************************************
50  * Local prototypes
51  *****************************************************************************/
52 
53 typedef struct {
54     int32_t i_preview_width, i_preview_lines;
55     int32_t i_border_width, i_border_lines;
56     int32_t i_pce_max_width, i_pce_max_lines;
57     int32_t i_width, i_lines, i_pitch, i_visible_pitch;
58     uint8_t i_pixel_pitch;
59 } puzzle_plane_t;
60 
61 typedef struct {
62     int32_t i_x, i_y;
63     int32_t i_width, i_lines;
64 } puzzle_array_t;
65 
66 typedef struct {
67     int32_t i_original_row, i_original_col;
68     int32_t i_top_shape, i_btm_shape, i_right_shape, i_left_shape;
69     float f_pos_x, f_pos_y;
70     int8_t i_actual_angle;                   /* 0 = 0°, 1 = 90°... rotation center = top-left corner */
71     int32_t i_actual_mirror;                 /* +1 = without mirror ; -1 = with mirror               */
72 } save_piece_t;
73 
74 typedef struct {
75     int32_t i_rows, i_cols;
76     uint8_t i_rotate;
77     save_piece_t *ps_pieces;
78 } save_game_t;
79 
80 typedef struct {
81     int32_t i_rows, i_cols;
82     int32_t i_pict_width, i_pict_height;
83     int32_t i_desk_width, i_desk_height;
84     int32_t i_piece_types;
85     uint32_t i_pieces_nbr;
86     int32_t i_preview_size;
87     int32_t i_shape_size;
88     int32_t i_border;
89     uint8_t i_planes;
90     /* game settings */
91     bool    b_preview;
92     bool b_blackslot;
93     bool b_near;
94     bool b_advanced;
95     uint8_t i_mode;
96     uint8_t i_rotate;   /* 0=none, 1=0/180, 2=0/90/180/270, 3=0/90/180/270 w/ mirror */
97     int32_t i_auto_shuffle_speed, i_auto_solve_speed;
98 } param_t;
99 
100 int  puzzle_bake ( filter_t *, picture_t * , picture_t * );
101 void puzzle_free_ps_puzzle_array ( filter_t * );
102 int  puzzle_bake_piece ( filter_t * );
103 void puzzle_set_left_top_shapes( filter_t *p_filter);
104 void puzzle_random_rotate( filter_t *p_filter);
105 void puzzle_free_ps_pieces ( filter_t * );
106 int  puzzle_allocate_ps_pieces( filter_t *p_filter);
107 
108 bool puzzle_is_valid( filter_sys_t *p_sys, int32_t *pi_pce_lst );
109 int  puzzle_shuffle( filter_t * );
110 int  puzzle_generate_rand_pce_list( filter_t *p_filter, int32_t **pi_pce_lst );
111 bool puzzle_is_finished( filter_sys_t *, int32_t *pi_pce_lst );
112 int  puzzle_piece_foreground( filter_t *p_filter, int32_t i_piece);
113 void puzzle_count_pce_group( filter_t *p_filter);
114 void puzzle_solve_pces_group( filter_t *p_filter);
115 void puzzle_solve_pces_accuracy( filter_t *p_filter);
116 int  puzzle_sort_layers( filter_t *p_filter);
117 
118 void puzzle_auto_solve( filter_t *p_filter);
119 void puzzle_auto_shuffle( filter_t *p_filter);
120 
121 save_game_t* puzzle_save(filter_t *p_filter);
122 void         puzzle_load( filter_t *p_filter, save_game_t *ps_save_game);
123 
124 #endif
125