2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
21 /*---------------------------------------------------------------------------*/
23 static float state_time;
24 static int state_drawn;
25 static struct state *state;
27 struct state *curr_state(void)
32 float time_state(void)
37 void init_state(struct state *st)
42 int goto_state(struct state *st)
44 struct state *prev = state;
46 if (state && state->leave)
47 state->leave(state, st, state->gui_id);
53 if (state && state->enter)
54 state->gui_id = state->enter(state, prev);
59 /*---------------------------------------------------------------------------*/
61 void st_paint(float t)
63 int stereo = config_get_d(CONFIG_STEREO);
67 if (state && state->paint)
71 glDrawBuffer(GL_BACK_LEFT);
73 state->paint(state->gui_id, t);
75 glDrawBuffer(GL_BACK_RIGHT);
77 state->paint(state->gui_id, t);
82 state->paint(state->gui_id, t);
87 void st_timer(float dt)
94 if (state && state->timer)
95 state->timer(state->gui_id, dt);
98 void st_point(int x, int y, int dx, int dy)
100 if (state && state->point)
101 state->point(state->gui_id, x, y, dx, dy);
104 void st_stick(int a, float v)
113 { &CONFIG_JOYSTICK_AXIS_X, &CONFIG_JOYSTICK_AXIS_X_INVERT },
114 { &CONFIG_JOYSTICK_AXIS_Y, &CONFIG_JOYSTICK_AXIS_Y_INVERT },
115 { &CONFIG_JOYSTICK_AXIS_U, &CONFIG_JOYSTICK_AXIS_U_INVERT }
120 for (i = 0; i < ARRAYSIZE(axes); i++)
121 if (config_tst_d(*axes[i].num, a))
123 float p = axes[i].prev;
125 /* Note the transition from centered to leaned position. */
127 bump = ((-0.5f <= p && p <= +0.5f) &&
128 (v < -0.5f || +0.5f < v));
132 if (config_get_d(*axes[i].inv))
138 if (state && state->stick)
139 state->stick(state->gui_id, a, v, bump);
142 void st_angle(int x, int z)
144 if (state && state->angle)
145 state->angle(state->gui_id, x, z);
148 /*---------------------------------------------------------------------------*/
150 int st_click(int b, int d)
152 return (state && state->click) ? state->click(b, d) : 1;
155 int st_keybd(int c, int d)
157 return (state && state->keybd) ? state->keybd(c, d) : 1;
160 int st_buttn(int b, int d)
162 return (state && state->buttn) ? state->buttn(b, d) : 1;
165 /*---------------------------------------------------------------------------*/