OVR: Make adjustments to the game's input using controllers
[mercenary-reloaded.git] / src / mercenary / main.c
index 0bd216d..d9fb1c7 100644 (file)
@@ -71,10 +71,10 @@ static double config_fov = FOV_JOLLY;
 static double config_benson_size = 1.0;
 static double config_fov = FOV_NOVAGEN;
 #endif
-static double config_monitor_distance = 31.5; /* inch */
+static double config_monitor_distance = 41.5; /* inch */
 #ifdef HAVE_OVR
-static double config_keyboard_distance = 28.5; /* inch */
-static double config_keyboard_height = 4.0; /* inch */
+static double config_keyboard_distance = 40.5; /* inch */
+static double config_keyboard_height = -26.0; /* inch */
 #endif
 static int config_debug_transparent = 0;
 static int config_debug_opengl = 0;
@@ -83,6 +83,7 @@ static int config_improve_extend_roads = 1;   /* set to 1 to extend roads */
 static int config_improve_smooth_planets = 1;  /* set to 1 to rotate planets smoothly */
 static int config_improve_stars_rotation = 1;  /* set to 1 to improve star rendering */
 static int config_improve_fix_sky_rotation = 0;        /* set to 1 to fix sky rotation */
+static int config_improve_round_planets = 0;   /* set to 1 to make planets exactly round */
 
 #define CPU_SPEED      7093790.0;
 
@@ -186,6 +187,11 @@ int parse_args(int argc, char *argv[])
                        print_info("        fixed by rotating all sky object by 180 degrees. The original (wrong)\n");
                        print_info("        rotation is default, because it preserves the game's spirit!\n");
                        print_info("        This option requires OpenGL rendering. (default = %d)\n", config_improve_fix_sky_rotation);
+                       print_info("    --round-planets 1 | 0\n");
+                       print_info("        The original game renders planets and explosion debris horizontally\n");
+                       print_info("        stretched. This compensates the vertical stretch of NTSC vs PAL video.\n");
+                       print_info("        The original (stretched) sphere makes the game authentic.\n");
+                       print_info("        This option requires OpenGL rendering. (default = %d)\n", config_improve_round_planets);
                        print_info("Debug options:\n");
                        print_info(" -o --debug-opengl\n");
                        print_info("        Use split screen to display both Amiga and OpenGL rendering.\n");
@@ -312,6 +318,12 @@ illegal_parameter:
                                goto missing_parameter;
                        config_improve_fix_sky_rotation = atoi(argv[i]);
                } else
+               if (!strcmp(argv[i], "--round-planets")) {
+                       i++;
+                       if (argc == i)
+                               goto missing_parameter;
+                       config_improve_round_planets = atoi(argv[i]);
+               } else
                if (!strcmp(argv[i], "-o") || !strcmp(argv[i], "--debug-opengl")) {
                        config_debug_opengl = 1;
                } else
@@ -368,7 +380,7 @@ static void handle_vr_poses(void)
        double hand_right_yaw = 0.0, hand_right_pitch = 0.0, hand_right_roll = 0.0;
        double head_yaw = 0.0, head_pitch = 0.0, head_roll = 0.0;
        double stick_left_x = 0.0, stick_left_y = 0.0, stick_right_x = 0.0, stick_right_y = 0.0;
-       int thrust = 0;
+       int thrust = thrust_last;
        int joystick_set_x = 0, joystick_set_y = 0;
        static uint32_t current_time, last_time = 0, diff;
        static double increment, inc_count = 0.0;
@@ -382,49 +394,40 @@ static void handle_vr_poses(void)
                else
                        help_view++;
        }
-       if (button_left_trigger && button_right_trigger) {
+       if (button_left_thumb) {
                /* reset observer */
                reset_observer_ovr();
                osd_info("", "reset observer");
        }
        if (!help_view) {
-               if (button_a && !button_a_last) {
-                       /* keyboard A toggle */
-                       if (keyboard_on == 1)
-                               keyboard_on = 0;
-                       else
-                               keyboard_on = 1;
-               }
-               if (button_b && !button_b_last) {
-                       /* keyboard B toggle */
-                       if (keyboard_on == 2)
-                               keyboard_on = 0;
-                       else
-                               keyboard_on = 2;
-               }
                if (button_x && !button_x_last) {
                        /* 'board' pressed */
                        set_amiga_key(KEYCODE_b, 1);
                        set_amiga_key(KEYCODE_b, 0);
+                       /* important: get rid of old state */
+                       thrust = 0;
                }
                if (button_y && !button_y_last) {
                        /* 'leave' pressed */
                        set_amiga_key(KEYCODE_l, 1);
                        set_amiga_key(KEYCODE_l, 0);
                }
-               if (button_right_thumb && !button_right_thumb_last) {
-                       /* 'change orientation' pressed */
-                       double roll, pitch, yaw;
-                       mercenary_get_orientation(&roll, &pitch, &yaw);
-                       mercenary_set_orientation(yaw + hand_right_yaw);
-               }
                if (button_right_trigger && !button_right_trigger_last) {
                        /* trigger pressed */
-                       if (!keyboard_on) {
+                       if (keyboard_on) {
+                               if (vr_key) {
+                                       vr_key_pressed = vr_key;
+                                       set_amiga_key(vr_key_pressed, 1);
+                               }
+                       } else
+                       if (mercenary_get_info_walking()) {
+                               /* change orientation */
+                               double roll, pitch, yaw;
+                               mercenary_get_orientation(&roll, &pitch, &yaw);
+                               mercenary_set_orientation(yaw + hand_right_yaw);
+                       } else {
+                               /* fire button */
                                set_joystick(-1, -1, -1, -1, 1);
-                       } else if (vr_key) {
-                               vr_key_pressed = vr_key;
-                               set_amiga_key(vr_key_pressed, 1);
                        }
                }
                if (!button_right_trigger && button_right_trigger_last) {
@@ -522,9 +525,8 @@ static void handle_vr_poses(void)
                if (joystick_set_y_last && !joystick_set_y)
                        set_joystick(-1, -1, 0, 0, -1);
                /* thrust */
-               thrust = thrust_last;
                /* button to toggle between stop and escape */
-               if (button_left_thumb && !button_left_thumb_last) {
+               if (button_left_trigger && !button_left_trigger_last) {
                        /* 'escape' pressed */
                        if (thrust_last == 0)
                                thrust = -99;
@@ -602,8 +604,7 @@ static void handle_vr_poses(void)
        /* we must handle keyboard after toggeling keyboard_on,
         * so that keyboard_on will not change until keyboard is rendered */
        vr_key = 0;
-       if (keyboard_on)
-               handle_vr_keyboard(keyboard_on - 1, hand_right_x, hand_right_y, hand_right_z, hand_right_yaw, hand_right_pitch, &vr_key);
+       keyboard_on = handle_vr_keyboard(hand_right_x, hand_right_y, hand_right_z, hand_right_yaw, hand_right_pitch, &vr_key);
 }
 #endif
 
@@ -664,8 +665,12 @@ static void main_loop(void)
        double render_delay = 0.0;
        uint32_t palette_address;
        uint16_t palette[16];
+       int all_white = 0;
 #ifdef HAVE_OVR
        int eye;
+       int vr = 1;
+#else
+       int vr = 0;
 #endif
 
        last_time = ticks_sdl();
@@ -714,7 +719,7 @@ static void main_loop(void)
                        frame_render = 0;
                        /* start capturing for improved graphics */
                        if (render_improved)
-                               render_capture_start(config_fov, config_improve_extend_roads, config_improve_smooth_planets, config_improve_stars_rotation, config_improve_fix_sky_rotation, config_debug_transparent);
+                               render_capture_start(config_fov, config_improve_extend_roads, config_improve_smooth_planets, config_improve_stars_rotation, config_improve_fix_sky_rotation, config_improve_round_planets, config_debug_transparent);
 
                        /* execute until the rendered image is ready (wait for VBL) */
                        cycle_count = 0;
@@ -749,11 +754,7 @@ static void main_loop(void)
                {
 #endif
                        /* clear screen */
-#ifdef HAVE_OVR
-                       opengl_clear(1);
-#else
-                       opengl_clear(0);
-#endif
+                       opengl_clear(vr);
                        /* render benson + osd ontop of improved opengl rendering, if enabled */
                        if (render_improved) {
 #ifndef HAVE_OVR
@@ -763,30 +764,17 @@ static void main_loop(void)
                                /* render improved graphics, interpolate, if required,
                                 * if no item list is available, for legacy rendering
                                 */
-#ifdef HAVE_OVR
-                               rc = render_all_items((config_amiga_speed) ? 1.0 : frame_time, 1);
-#else
-                               rc = render_all_items((config_amiga_speed) ? 1.0 : frame_time, 0);
-#endif
+                               if (all_white)
+                                       rc = render_all_white(vr);
+                               else
+                                       rc = render_all_items((config_amiga_speed) ? 1.0 : frame_time, vr);
                                if (rc)
                                        goto goto_legacy;
-#ifdef HAVE_OVR
-                               opengl_blit_image(image, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, 1, config_fov, config_monitor_distance, benson_size, 1);
-#else
-                               opengl_blit_image(image, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, 1, config_fov, config_monitor_distance, benson_size, 0);
-#endif
+                               opengl_blit_image(image, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, 1, config_fov, config_monitor_distance, benson_size, vr);
                                if (help_view)
-#ifdef HAVE_OVR
-                                       opengl_blit_osd(0, help_osd[help_view - 1], config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, FOV_NOVAGEN, config_monitor_distance, 1.0, 1.0, 1.0, 0.0, 0.0);
-#else
-                                       opengl_blit_osd(0, help_osd[help_view - 1], config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, config_fov, config_monitor_distance, benson_size, 1.0, 1.0, 0.0, 0.0);
-#endif
+                                       opengl_blit_osd(0, help_osd[help_view - 1], config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, (vr) ? FOV_NOVAGEN : config_fov, config_monitor_distance, (vr) ? 1.0 : benson_size, 1.0, 1.0, 0.0, 0.0);
                                if (osd_timer) {
-#ifdef HAVE_OVR
-                                       opengl_blit_osd(1, info_osd, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, FOV_NOVAGEN, config_monitor_distance, 1.0, 0.5, 0.04, 0.5, -0.95);
-#else
-                                       opengl_blit_osd(1, info_osd, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, config_fov, config_monitor_distance, benson_size, 0.5, 0.04, 0.5, -0.95);
-#endif
+                                       opengl_blit_osd(1, info_osd, config_video_filter, (double_pixel_size) ? BENSON_AT_LINE * 2 : BENSON_AT_LINE, (vr) ? FOV_NOVAGEN : config_fov, config_monitor_distance, (vr) ? 1.0 : benson_size, 0.5, 0.04, 0.5, -0.95);
                                        if (osd_timer - (int32_t)ticks_sdl() < 0)
                                                osd_timer = 0;
                                }
@@ -816,7 +804,7 @@ static void main_loop(void)
 #ifdef HAVE_OVR
                        /* render keyboard */
                        if (keyboard_on)
-                               render_vr_keyboard(keyboard_on - 1, camera_x, camera_y);
+                               render_vr_keyboard(camera_x, camera_y);
 
                        /* end of rendering eye */
                        end_render_ovr_eye(eye);
@@ -859,7 +847,7 @@ static void main_loop(void)
                                /* transfer benson without game view
                                 * because we only got benson refreshed during VBL IRQ
                                 */
-                               emul_video(image, memory, palette, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_DIWSTART, chipreg, BENSON_AT_LINE, IMAGE_HEIGHT, double_pixel_size);
+                               all_white = emul_video(image, memory, palette, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_DIWSTART, chipreg, BENSON_AT_LINE, IMAGE_HEIGHT, double_pixel_size);
                                /* render sound to sound buffer
                                 * buffer pointer read and write is atomic, so no locking required!
                                 */
@@ -1295,18 +1283,18 @@ int main(int argc, char *argv[])
        /* init SDL and OpenGL */
 #ifdef HAVE_OVR
        int vbl_sync = 0;
-       int rift = 1;
+       int vr = 1;
        int multisampling = 0;
        window_width = SCREEN_WIDTH;
        window_height = SCREEN_HEIGHT;
 #else
        int vbl_sync = 1;
-       int rift = 0;
+       int vr = 0;
        int multisampling = config_multisampling;
        window_width = (config_debug_opengl) ? SCREEN_WIDTH / 3 * 2 : SCREEN_WIDTH;
        window_height = (config_debug_opengl) ? SCREEN_HEIGHT / 3 * 4 : SCREEN_HEIGHT;
 #endif
-       rc = init_sdl(argv[0], window_width, window_height, SOUND_SAMPLERATE, sdl_sound_chunk, keyboard_sdl, audio_sdl, resize_window, multisampling, vbl_sync, rift);
+       rc = init_sdl(argv[0], window_width, window_height, SOUND_SAMPLERATE, sdl_sound_chunk, keyboard_sdl, audio_sdl, resize_window, multisampling, vbl_sync, vr);
        if (rc < 0)
                goto done;
 #ifdef HAVE_OVR
@@ -1385,24 +1373,22 @@ int main(int argc, char *argv[])
        text_render(help_osd[1], IMAGE_WIDTH * 2, IMAGE_HEIGHT * 2,
                "Emulation using Controller:\n"
                "        Press `Enter' button to toggle this help screen on or off.\n"
-               "        Press `A' button to emulate keyboard to control game.\n"
-               "        Press `B' button to emulate keyboard to enter alphanumeric keys.\n"
-               "        Press `A' or `B' button again to dismiss keyboard.\n"
-               "        Point right controller to a key on keyboard. The key will highlight.\n"
-               "        Pull `Trigger' on right controller enter the highlighted key.\n"
-               "        Pull `Trigger' on both controllers to reset observer position.\n"
+               "        To have a virtual keyboard, point below benson (control pannel).\n"
+               "        Point to a key on keyboard. The key will highlight.\n"
+               "        Pull `Trigger' on right controller to enter the highlighted key.\n"
+               "        Press thumb stick on left controller to reset observer position.\n"
                "\n"
                "Walking / Driving / Flying using Controller:\n"
                "        Use thumb stick on right controller, to move player / craft.\n"
                "        Point right controller towards the direction to walk to.\n"
-               "        Press thumb stick to change orientation to that direction.\n"
+               "        Pull `Trigger' on right controller to change orientation.\n"
                "        Press `X' button to board, `Y' button to leave.\n"
                "        Move thumb stick on left controller to drive/fly forward or backward.\n"
-               "        Press thumb stick on left controller stop craft.\n"
-               "        Press thumb stick on left controller for escape sequence, after stop.\n"
+               "        Pull `Trigger' on left controller stop craft.\n"
+               "        Pull `Trigger' on left controller for escape sequence, after stop.\n"
                "        Pull `Trigger' on right controller to fire.\n"
                "\n"
-               "For all other game function, use the emulated keyboards!\n"
+               "For all other game function, use the virtual or real keyboard!\n"
                ,HELP_ALPHA, 1, 2, 5, 0);
        help_views = 2;
 #endif