2 * Copyright (C) 2003 Robert Kooima
4 * NEVERPUTT 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.
15 /*---------------------------------------------------------------------------*/
42 const char TITLE[] = "Neverputt " VERSION;
43 const char ICON[] = "icon/neverputt.png";
45 /*---------------------------------------------------------------------------*/
47 static int shot_pending;
49 static void shot_prep(void)
54 static void shot_take(void)
56 static char filename[MAXSTR];
60 sprintf(filename, "Screenshots/screen%05d.png", config_screenshot());
66 /*---------------------------------------------------------------------------*/
68 static void toggle_wire(void)
75 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
76 glEnable(GL_TEXTURE_2D);
77 glEnable(GL_LIGHTING);
82 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
83 glDisable(GL_TEXTURE_2D);
84 glDisable(GL_LIGHTING);
89 /*---------------------------------------------------------------------------*/
97 while (d && SDL_PollEvent(&e))
99 if (e.type == SDL_QUIT)
104 case SDL_MOUSEMOTION:
105 st_point(+e.motion.x,
106 -e.motion.y + config_get_d(CONFIG_HEIGHT),
111 case SDL_MOUSEBUTTONDOWN:
112 d = st_click(e.button.button, 1);
115 case SDL_MOUSEBUTTONUP:
116 d = st_click(e.button.button, 0);
121 c = e.key.keysym.sym;
123 if (config_tst_d(CONFIG_KEY_FORWARD, c))
124 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -1.0f);
126 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
127 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +1.0f);
129 else if (config_tst_d(CONFIG_KEY_LEFT, c))
130 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -1.0f);
132 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
133 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +1.0f);
137 case SDLK_F10: shot_prep(); break;
138 case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
139 case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
140 case SDLK_F7: toggle_wire(); break;
143 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
146 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1);
150 d = st_keybd(e.key.keysym.sym, 1);
156 c = e.key.keysym.sym;
158 if (config_tst_d(CONFIG_KEY_FORWARD, c))
159 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0.0f);
161 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
162 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0.0f);
164 else if (config_tst_d(CONFIG_KEY_LEFT, c))
165 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0.0f);
167 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
168 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0.0f);
173 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0);
176 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0);
180 d = st_keybd(e.key.keysym.sym, 0);
184 case SDL_ACTIVEEVENT:
185 if (e.active.state == SDL_APPINPUTFOCUS)
186 if (e.active.gain == 0 && video_get_grab())
187 goto_pause(&st_over, 0);
190 case SDL_JOYAXISMOTION:
191 st_stick(e.jaxis.axis, JOY_VALUE(e.jaxis.value));
194 case SDL_JOYBUTTONDOWN:
195 d = st_buttn(e.jbutton.button, 1);
198 case SDL_JOYBUTTONUP:
199 d = st_buttn(e.jbutton.button, 0);
206 int main(int argc, char *argv[])
209 SDL_Joystick *joy = NULL;
211 if (!fs_init(argv[0]))
213 fprintf(stderr, "Failure to initialize virtual file system: %s\n",
218 srand((int) time(NULL));
220 lang_init("neverball");
221 config_paths(argc > 1 ? argv[1] : NULL);
222 fs_mkdir("Screenshots");
224 if (SDL_Init(SDL_INIT_VIDEO |
229 SDL_INIT_JOYSTICK) == 0)
234 /* Cache Neverball's camera setting. */
236 camera = config_get_d(CONFIG_CAMERA);
238 /* Initialize the joystick. */
240 if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0)
242 joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
245 SDL_JoystickEventState(SDL_ENABLE);
250 /* Initialize the audio. */
255 maemo_init("neverputt");
258 /* Initialize the video. */
260 if (video_init(TITLE, ICON))
262 int t1, t0 = SDL_GetTicks();
264 /* Run the main game loop. */
266 init_state(&st_null);
267 goto_state(&st_title);
270 if ((t1 = SDL_GetTicks()) > t0)
272 st_timer((t1 - t0) / 1000.f);
273 st_paint(0.001f * t1);
275 SDL_GL_SwapBuffers();
279 if (config_get_d(CONFIG_NICE))
284 /* Restore Neverball's camera setting. */
286 config_set_d(CONFIG_CAMERA, camera);
291 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
296 /*---------------------------------------------------------------------------*/