Merge branch 'gles'
[neverball] / putt / main.c
index f847bc6..1c173da 100644 (file)
@@ -41,19 +41,30 @@ 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(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)
@@ -70,6 +81,7 @@ static void toggle_wire(void)
         glDisable(GL_LIGHTING);
         wire = 1;
     }
+#endif
 }
 /*---------------------------------------------------------------------------*/
 
@@ -106,20 +118,20 @@ static int loop(void)
             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;
@@ -140,19 +152,17 @@ static int loop(void)
 
             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)
             {
@@ -166,6 +176,7 @@ static int loop(void)
             default:
                 d = st_keybd(e.key.keysym.sym, 0);
             }
+            break;
 
         case SDL_ACTIVEEVENT:
             if (e.active.state == SDL_APPINPUTFOCUS)
@@ -174,7 +185,7 @@ static int loop(void)
             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:
@@ -196,7 +207,8 @@ int main(int argc, char *argv[])
 
     if (!fs_init(argv[0]))
     {
-        fputs("Failure to initialize virtual file system\n", stderr);
+        fprintf(stderr, "Failure to initialize virtual file system: %s\n",
+                fs_error());
         return 1;
     }
 
@@ -204,6 +216,7 @@ int main(int argc, char *argv[])
 
     lang_init("neverball");
     config_paths(argc > 1 ? argv[1] : NULL);
+    fs_mkdir("Screenshots");
 
     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
     {
@@ -216,7 +229,7 @@ int main(int argc, char *argv[])
 
         /* Initialize the joystick. */
 
-        if (SDL_NumJoysticks() > 0)
+        if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0)
         {
             joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
             if (joy)
@@ -246,6 +259,7 @@ int main(int argc, char *argv[])
                 {
                     st_timer((t1 - t0) / 1000.f);
                     st_paint(0.001f * t1);
+                    shot_take();
                     SDL_GL_SwapBuffers();
 
                     t0 = t1;