File: cmd.h

package info (click to toggle)
neverball 1.6.0%2Bgit20180603-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 152,384 kB
  • sloc: ansic: 27,402; makefile: 454; cpp: 208; xml: 177; sh: 161
file content (364 lines) | stat: -rw-r--r-- 6,580 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*
 * Copyright (C) 2009 Neverball authors
 *
 * NEVERBALL is  free software; you can redistribute  it and/or modify
 * it under the  terms of the GNU General  Public License as published
 * by the Free  Software Foundation; either version 2  of the License,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
 * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
 * General Public License for more details.
 */

#ifndef CMD_H
#define CMD_H

/*
 * In an attempt to improve replay compatibility, a few guidelines
 * apply to command addition, removal, and modification:
 *
 * - New commands are added at the bottom of the list.
 * - Existing commands are never modified nor removed.
 * - The list is never reordered.  (It's tempting.)
 *
 * However, commands can be renamed (e.g., to add a "deprecated" tag,
 * because it's superseded by another command).
 */

enum cmd_type
{
    CMD_NONE = 0,

    CMD_END_OF_UPDATE,
    CMD_MAKE_BALL,
    CMD_MAKE_ITEM,
    CMD_PICK_ITEM,
    CMD_TILT_ANGLES,
    CMD_SOUND,
    CMD_TIMER,
    CMD_STATUS,
    CMD_COINS,
    CMD_JUMP_ENTER,
    CMD_JUMP_EXIT,
    CMD_BODY_PATH,
    CMD_BODY_TIME,
    CMD_GOAL_OPEN,
    CMD_SWCH_ENTER,
    CMD_SWCH_TOGGLE,
    CMD_SWCH_EXIT,
    CMD_UPDATES_PER_SECOND,
    CMD_BALL_RADIUS,
    CMD_CLEAR_ITEMS,
    CMD_CLEAR_BALLS,
    CMD_BALL_POSITION,
    CMD_BALL_BASIS,
    CMD_BALL_PEND_BASIS,
    CMD_VIEW_POSITION,
    CMD_VIEW_CENTER,
    CMD_VIEW_BASIS,
    CMD_CURRENT_BALL,
    CMD_PATH_FLAG,
    CMD_STEP_SIMULATION,
    CMD_MAP,
    CMD_TILT_AXES,
    CMD_MOVE_PATH,
    CMD_MOVE_TIME,

    CMD_MAX
};

/*
 * Here are the members common to all structures.  Note that it
 * explicitly says "enum cmd_type", not "int".  This allows GCC to
 * catch and warn about unhandled command types in switch constructs
 * (handy when adding new commands).
 */

#define CMD_HEADER \
    enum cmd_type type

struct cmd_end_of_update
{
    CMD_HEADER;
};

struct cmd_make_ball
{
    CMD_HEADER;
};

struct cmd_make_item
{
    CMD_HEADER;
    float p[3];
    int   t;
    int   n;
};

struct cmd_pick_item
{
    CMD_HEADER;
    int   hi;
};

struct cmd_tilt_angles
{
    CMD_HEADER;
    float x;
    float z;
};

struct cmd_sound
{
    CMD_HEADER;
    char  *n;
    float  a;
};

struct cmd_timer
{
    CMD_HEADER;
    float t;
};

struct cmd_status
{
    CMD_HEADER;
    int t;
};

struct cmd_coins
{
    CMD_HEADER;
    int n;
};

struct cmd_jump_enter
{
    CMD_HEADER;
};

struct cmd_jump_exit
{
    CMD_HEADER;
};

struct cmd_body_path
{
    CMD_HEADER;
    int bi;
    int pi;
};

struct cmd_body_time
{
    CMD_HEADER;
    int   bi;
    float t;
};

struct cmd_goal_open
{
    CMD_HEADER;
};

struct cmd_swch_enter
{
    CMD_HEADER;
    int xi;
};

struct cmd_swch_toggle
{
    CMD_HEADER;
    int xi;
};

struct cmd_swch_exit
{
    CMD_HEADER;
    int xi;
};

struct cmd_updates_per_second
{
    CMD_HEADER;
    int n;
};

struct cmd_ball_radius
{
    CMD_HEADER;
    float r;
};

struct cmd_clear_items
{
    CMD_HEADER;
};

struct cmd_clear_balls
{
    CMD_HEADER;
};

struct cmd_ball_position
{
    CMD_HEADER;
    float p[3];
};

struct cmd_ball_basis
{
    CMD_HEADER;
    float e[2][3];
};

struct cmd_ball_pend_basis
{
    CMD_HEADER;
    float E[2][3];
};

struct cmd_view_position
{
    CMD_HEADER;
    float p[3];
};

struct cmd_view_center
{
    CMD_HEADER;
    float c[3];
};

struct cmd_view_basis
{
    CMD_HEADER;
    float e[2][3];
};

struct cmd_current_ball
{
    CMD_HEADER;
    int ui;
};

struct cmd_path_flag
{
    CMD_HEADER;
    int pi;
    int f;
};

struct cmd_step_simulation
{
    CMD_HEADER;
    float dt;
};

struct cmd_map
{
    CMD_HEADER;
    char *name;
    struct
    {
        int x, y;
    } version;
};

struct cmd_tilt_axes
{
    CMD_HEADER;
    float x[3], z[3];
};

struct cmd_move_path
{
    CMD_HEADER;
    int mi;
    int pi;
};

struct cmd_move_time
{
    CMD_HEADER;
    int   mi;
    float t;
};

union cmd
{
    enum cmd_type type;

    struct { CMD_HEADER; } header;

    struct cmd_end_of_update      eou;
    struct cmd_make_ball          mkball;
    struct cmd_make_item          mkitem;
    struct cmd_pick_item          pkitem;
    struct cmd_tilt_angles        tiltangles;
    struct cmd_sound              sound;
    struct cmd_timer              timer;
    struct cmd_status             status;
    struct cmd_coins              coins;
    struct cmd_jump_enter         jumpenter;
    struct cmd_jump_exit          jumpexit;
    struct cmd_body_path          bodypath;
    struct cmd_body_time          bodytime;
    struct cmd_goal_open          goalopen;
    struct cmd_swch_enter         swchenter;
    struct cmd_swch_toggle        swchtoggle;
    struct cmd_swch_exit          swchexit;
    struct cmd_updates_per_second ups;
    struct cmd_ball_radius        ballradius;
    struct cmd_clear_items        clritems;
    struct cmd_clear_balls        clrballs;
    struct cmd_ball_position      ballpos;
    struct cmd_ball_basis         ballbasis;
    struct cmd_ball_pend_basis    ballpendbasis;
    struct cmd_view_position      viewpos;
    struct cmd_view_center        viewcenter;
    struct cmd_view_basis         viewbasis;
    struct cmd_current_ball       currball;
    struct cmd_path_flag          pathflag;
    struct cmd_step_simulation    stepsim;
    struct cmd_map                map;
    struct cmd_tilt_axes          tiltaxes;
    struct cmd_move_path          movepath;
    struct cmd_move_time          movetime;
};

#undef CMD_HEADER

#include "fs.h"

int cmd_put(fs_file, const union cmd *);
int cmd_get(fs_file, union cmd *);

void cmd_free(union cmd *);

/*---------------------------------------------------------------------------*/

struct cmd_state
{
    int ups;                            /* Updates per second                */
    int first_update;                   /* First update flag                 */
    int next_update;                    /* Previous command was EOU          */
    int curr_ball;                      /* Current ball index                */
    int got_tilt_axes;                  /* Received tilt axes in this update */
};

#define cmd_state_init(cs) do { \
    (cs)->ups = 0;              \
    (cs)->first_update = 1;     \
    (cs)->next_update = 0;      \
    (cs)->curr_ball = 0;        \
    (cs)->got_tilt_axes = 0;    \
} while (0)

/*---------------------------------------------------------------------------*/

#endif