#include "image.h"
#include "state.h"
#include "config.h"
+#include "video.h"
#include "course.h"
#include "hole.h"
#include "game.h"
#include "gui.h"
-#include "text.h"
-#include "syswm.h"
+#include "fs.h"
#include "st_conf.h"
#include "st_all.h"
-#define TITLE "Neverputt " VERSION
+const char TITLE[] = "Neverputt " VERSION;
+const char ICON[] = "icon/neverputt.png";
/*---------------------------------------------------------------------------*/
-static int shot(void)
+static int shot_pending;
+
+static void shot_prep(void)
{
- static char filename[MAXSTR];
+ shot_pending = 1;
+}
- sprintf(filename, "screen%05d.png", config_screenshot());
- image_snap(config_user(filename));
+static void shot_take(void)
+{
+ static char filename[MAXSTR];
- return 1;
+ if (shot_pending)
+ {
+ sprintf(filename, "Screenshots/screen%05d.png", config_screenshot());
+ image_snap(filename);
+ shot_pending = 0;
+ }
}
+
/*---------------------------------------------------------------------------*/
static void toggle_wire(void)
{
+#if !ENABLE_OPENGLES
static int wire = 0;
if (wire)
glDisable(GL_LIGHTING);
wire = 1;
}
+#endif
}
/*---------------------------------------------------------------------------*/
c = e.key.keysym.sym;
if (config_tst_d(CONFIG_KEY_FORWARD, c))
- st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX);
+ st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -1.0f);
else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
- st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX);
+ st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +1.0f);
else if (config_tst_d(CONFIG_KEY_LEFT, c))
- st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX);
+ st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -1.0f);
else if (config_tst_d(CONFIG_KEY_RIGHT, c))
- st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX);
+ st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +1.0f);
else switch (c)
{
- case SDLK_F10: d = shot(); break;
+ case SDLK_F10: shot_prep(); break;
case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
case SDLK_F7: toggle_wire(); break;
c = e.key.keysym.sym;
- /* gui_stick needs a non-null value, so we use 1 instead of 0. */
-
if (config_tst_d(CONFIG_KEY_FORWARD, c))
- st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
+ st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0.0f);
else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
- st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
+ st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0.0f);
else if (config_tst_d(CONFIG_KEY_LEFT, c))
- st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
+ st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0.0f);
else if (config_tst_d(CONFIG_KEY_RIGHT, c))
- st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
+ st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0.0f);
else switch (c)
{
default:
d = st_keybd(e.key.keysym.sym, 0);
}
+ break;
case SDL_ACTIVEEVENT:
if (e.active.state == SDL_APPINPUTFOCUS)
- if (e.active.gain == 0 && config_get_grab())
+ if (e.active.gain == 0 && video_get_grab())
goto_pause(&st_over, 0);
break;
case SDL_JOYAXISMOTION:
- st_stick(e.jaxis.axis, e.jaxis.value);
+ st_stick(e.jaxis.axis, JOY_VALUE(e.jaxis.value));
break;
case SDL_JOYBUTTONDOWN:
int camera = 0;
SDL_Joystick *joy = NULL;
+ if (!fs_init(argv[0]))
+ {
+ fprintf(stderr, "Failure to initialize virtual file system: %s\n",
+ fs_error());
+ return 1;
+ }
+
srand((int) time(NULL));
- lang_init("neverball", CONFIG_LOCALE);
+ lang_init("neverball");
+ config_paths(argc > 1 ? argv[1] : NULL);
+ fs_mkdir("Screenshots");
- if (config_data_path((argc > 1 ? argv[1] : NULL), COURSE_FILE))
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
{
- if (config_user_path(NULL))
- {
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
- {
- config_init();
- config_load();
-
- /* Cache Neverball's camera setting. */
+ config_init();
+ config_load();
- camera = config_get_d(CONFIG_CAMERA);
+ /* Cache Neverball's camera setting. */
- /* Initialize the joystick. */
+ camera = config_get_d(CONFIG_CAMERA);
- if (SDL_NumJoysticks() > 0)
- {
- joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
- if (joy)
- {
- SDL_JoystickEventState(SDL_ENABLE);
- set_joystick(joy);
- }
- }
+ /* Initialize the joystick. */
- /* Initialize the audio. */
+ if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0)
+ {
+ joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
+ if (joy)
+ {
+ SDL_JoystickEventState(SDL_ENABLE);
+ set_joystick(joy);
+ }
+ }
- audio_init();
+ /* Initialize the audio. */
- /* Require 16-bit double buffer with 16-bit depth buffer. */
+ audio_init();
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ /* Initialize the video. */
- /* This has to happen before mode setting... */
+ if (video_init(TITLE, ICON))
+ {
+ int t1, t0 = SDL_GetTicks();
- set_SDL_icon("icon/neverputt.png");
+ /* Run the main game loop. */
- /* Initialize the video. */
+ init_state(&st_null);
+ goto_state(&st_title);
- if (config_mode(config_get_d(CONFIG_FULLSCREEN),
- config_get_d(CONFIG_WIDTH),
- config_get_d(CONFIG_HEIGHT)))
+ while (loop())
+ if ((t1 = SDL_GetTicks()) > t0)
{
- int t1, t0 = SDL_GetTicks();
-
- /* ... and this has to happen after it. */
+ st_timer((t1 - t0) / 1000.f);
+ st_paint(0.001f * t1);
+ shot_take();
+ SDL_GL_SwapBuffers();
- set_EWMH_icon("icon/neverputt.png");
+ t0 = t1;
- SDL_WM_SetCaption(TITLE, TITLE);
-
- /* Run the main game loop. */
-
- init_state(&st_null);
- goto_state(&st_title);
-
- while (loop())
- if ((t1 = SDL_GetTicks()) > t0)
- {
- st_timer((t1 - t0) / 1000.f);
- st_paint(0.001f * t1);
- SDL_GL_SwapBuffers();
-
- t0 = t1;
-
- if (config_get_d(CONFIG_NICE))
- SDL_Delay(1);
- }
+ if (config_get_d(CONFIG_NICE))
+ SDL_Delay(1);
}
- else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
+ }
- /* Restore Neverball's camera setting. */
+ /* Restore Neverball's camera setting. */
- config_set_d(CONFIG_CAMERA, camera);
- config_save();
+ config_set_d(CONFIG_CAMERA, camera);
+ config_save();
- SDL_Quit();
- }
- else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
- }
- else fprintf(stderr, L_("Failure to establish config directory\n"));
+ SDL_Quit();
}
- else fprintf(stderr, L_("Failure to establish game data directory\n"));
+ else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
return 0;
}