source: mainline/uspace/dist/src/c/demos/tetris/tetris.h

Last change on this file was b7fd2a0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** Attributations
30 *
31 * tetris.h 8.1 (Berkeley) 5/31/93
32 * NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd
33 * OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert
34 *
35 * Based upon BSD Tetris
36 *
37 * Copyright (c) 1992, 1993
38 * The Regents of the University of California.
39 * Distributed under BSD license.
40 *
41 * This code is derived from software contributed to Berkeley by
42 * Chris Torek and Darren F. Provine.
43 *
44 */
45
46/** @addtogroup tetris
47 * @{
48 */
49/** @file
50 */
51
52#include <stdint.h>
53
54/*
55 * Definitions for Tetris.
56 */
57
58/*
59 * The display (`board') is composed of 23 rows of 12 columns of characters
60 * (numbered 0..22 and 0..11), stored in a single array for convenience.
61 * Columns 1 to 10 of rows 1 to 20 are the actual playing area, where
62 * shapes appear. Columns 0 and 11 are always occupied, as are all
63 * columns of rows 21 and 22. Rows 0 and 22 exist as boundary areas
64 * so that regions `outside' the visible area can be examined without
65 * worrying about addressing problems.
66 */
67
68/* The board */
69#define B_COLS 12
70#define B_ROWS 23
71#define B_SIZE (B_ROWS * B_COLS)
72
73typedef uint32_t cell;
74
75extern cell board[B_SIZE]; /* 1 => occupied, 0 => empty */
76
77/* The displayed area (rows) */
78#define D_FIRST 1
79#define D_LAST 22
80
81/* The active area (rows) */
82#define A_FIRST 1
83#define A_LAST 21
84
85/*
86 * Minimum display size.
87 */
88#define MINROWS 23
89#define MINCOLS 40
90
91/* Current screen size */
92extern int Rows;
93extern int Cols;
94
95/*
96 * Translations from board coordinates to display coordinates.
97 * As with board coordinates, display coordiates are zero origin.
98 */
99#define RTOD(x) ((x) - 1)
100#define CTOD(x) ((x) * 2 + (((Cols - 2 * B_COLS) >> 1) - 1))
101
102/*
103 * A `shape' is the fundamental thing that makes up the game. There
104 * are 7 basic shapes, each consisting of four `blots':
105 *
106 * X.X X.X X.X
107 * X.X X.X X.X.X X.X X.X.X X.X.X X.X.X.X
108 * X X X
109 *
110 * 0 1 2 3 4 5 6
111 *
112 * Except for 3 and 6, the center of each shape is one of the blots.
113 * This blot is designated (0, 0). The other three blots can then be
114 * described as offsets from the center. Shape 3 is the same under
115 * rotation, so its center is effectively irrelevant; it has been chosen
116 * so that it `sticks out' upward and leftward. Except for shape 6,
117 * all the blots are contained in a box going from (-1, -1) to (+1, +1);
118 * shape 6's center `wobbles' as it rotates, so that while it `sticks out'
119 * rightward, its rotation---a vertical line---`sticks out' downward.
120 * The containment box has to include the offset (2, 0), making the overall
121 * containment box range from offset (-1, -1) to (+2, +1). (This is why
122 * there is only one row above, but two rows below, the display area.)
123 *
124 * The game works by choosing one of these shapes at random and putting
125 * its center at the middle of the first display row (row 1, column 5).
126 * The shape is moved steadily downward until it collides with something:
127 * either another shape, or the bottom of the board. When the shape can
128 * no longer be moved downwards, it is merged into the current board.
129 * At this time, any completely filled rows are elided, and blots above
130 * these rows move down to make more room. A new random shape is again
131 * introduced at the top of the board, and the whole process repeats.
132 * The game ends when the new shape will not fit at (1, 5).
133 *
134 * While the shapes are falling, the user can rotate them counterclockwise
135 * 90 degrees (in addition to moving them left or right), provided that the
136 * rotation puts the blots in empty spaces. The table of shapes is set up
137 * so that each shape contains the index of the new shape obtained by
138 * rotating the current shape. Due to symmetry, each shape has exactly
139 * 1, 2, or 4 rotations total; the first 7 entries in the table represent
140 * the primary shapes, and the remaining 12 represent their various
141 * rotated forms.
142 */
143struct shape {
144 int rot; /* index of rotated version of this shape */
145 int rotc; /* -- " -- in classic version */
146 int off[3]; /* offsets to other blots if center is at (0,0) */
147 uint32_t color;
148};
149
150extern const struct shape shapes[];
151
152extern const struct shape *curshape;
153extern const struct shape *nextshape;
154
155/*
156 * Shapes fall at a rate faster than once per second.
157 *
158 * The initial rate is determined by dividing 1 million microseconds
159 * by the game `level'. (This is at most 1 million, or one second.)
160 * Each time the fall-rate is used, it is decreased a little bit,
161 * depending on its current value, via the `faster' macro below.
162 * The value eventually reaches a limit, and things stop going faster,
163 * but by then the game is utterly impossible.
164 */
165extern long fallrate; /* less than 1 million; smaller => faster */
166
167#define faster() (fallrate -= fallrate / 3000)
168
169/*
170 * Game level must be between 1 and 9. This controls the initial fall rate
171 * and affects scoring.
172 */
173#define MINLEVEL 1
174#define MAXLEVEL 9
175
176/*
177 * Scoring is as follows:
178 *
179 * When the shape comes to rest, and is integrated into the board,
180 * we score one point. If the shape is high up (at a low-numbered row),
181 * and the user hits the space bar, the shape plummets all the way down,
182 * and we score a point for each row it falls (plus one more as soon as
183 * we find that it is at rest and integrate it---until then, it can
184 * still be moved or rotated).
185 *
186 * If previewing has been turned on, the score is multiplied by PRE_PENALTY.
187 */
188#define PRE_PENALTY 0.75
189
190extern int score; /* The obvious thing */
191
192extern char key_msg[100];
193extern int showpreview;
194extern int classic;
195
196extern errno_t fits_in(const struct shape *, int);
197extern void place(const struct shape *, int, int);
198extern void stop(const char *);
199
200/** @}
201 */
Note: See TracBrowser for help on using the repository browser.