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)
65 if (state && state->paint)
67 /* TODO: reimplement stereo using LR instead of quad-buffer.
69 if (config_get_d(CONFIG_STEREO))
71 glDrawBuffer(GL_BACK_LEFT);
73 state->paint(state->gui_id, t);
75 glDrawBuffer(GL_BACK_RIGHT);
77 state->paint(state->gui_id, t);
83 state->paint(state->gui_id, t);
88 void st_timer(float dt)
95 if (state && state->timer)
96 state->timer(state->gui_id, dt);
99 void st_point(int x, int y, int dx, int dy)
101 if (state && state->point)
102 state->point(state->gui_id, x, y, dx, dy);
105 void st_stick(int a, float v)
114 { &CONFIG_JOYSTICK_AXIS_X, &CONFIG_JOYSTICK_AXIS_X_INVERT },
115 { &CONFIG_JOYSTICK_AXIS_Y, &CONFIG_JOYSTICK_AXIS_Y_INVERT },
116 { &CONFIG_JOYSTICK_AXIS_U, &CONFIG_JOYSTICK_AXIS_U_INVERT }
121 for (i = 0; i < ARRAYSIZE(axes); i++)
122 if (config_tst_d(*axes[i].num, a))
124 float p = axes[i].prev;
126 /* Note the transition from centered to leaned position. */
128 bump = ((-0.5f <= p && p <= +0.5f) &&
129 (v < -0.5f || +0.5f < v));
133 if (config_get_d(*axes[i].inv))
139 if (state && state->stick)
140 state->stick(state->gui_id, a, v, bump);
143 void st_angle(float x, float z)
145 if (state && state->angle)
146 state->angle(state->gui_id, x, z);
149 /*---------------------------------------------------------------------------*/
151 int st_click(int b, int d)
153 return (state && state->click) ? state->click(b, d) : 1;
156 int st_keybd(int c, int d)
158 return (state && state->keybd) ? state->keybd(c, d) : 1;
161 int st_buttn(int b, int d)
163 return (state && state->buttn) ? state->buttn(b, d) : 1;
166 /*---------------------------------------------------------------------------*/