Changeset 816

Show
Ignore:
Timestamp:
03/25/08 19:49:01 (6 months ago)
Author:
ajps
Message:

Add the moderately well-tested "lazy movement" patch which allows a
movement delay to be set, during which it is possible to choose a second
direction. This means that up and left in quick succession can be
translated to an actual diagonal. This may improve some people's laptop
playing experience without resorting to the roguelike keyset.

Might fix #119, as it delays printing the movement prompt to avoid
flicker.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cmd4.c

    r815 r816  
    29092909 
    29102910                /* Do not wait for keys */ 
    2911                 inkey_scan = TRUE
     2911                inkey_scan = SCAN_INSTANT
    29122912 
    29132913                /* Attempt to read a key */ 
     
    39163916 
    39173917 
     3918bool askfor_aux_numbers(char *buf, size_t buflen, size_t *curs, size_t *len, char keypress, bool firsttime) 
     3919{ 
     3920        switch (keypress) 
     3921        { 
     3922                case ESCAPE: 
     3923                case '\n': 
     3924                case '\r': 
     3925                case ARROW_LEFT: 
     3926                case ARROW_RIGHT: 
     3927                case 0x7F: 
     3928                case '\010': 
     3929                case '0': 
     3930                case '1': 
     3931                case '2': 
     3932                case '3': 
     3933                case '4': 
     3934                case '5': 
     3935                case '6': 
     3936                case '7': 
     3937                case '8': 
     3938                case '9': 
     3939                        return askfor_aux_keypress(buf, buflen, curs, len, keypress, firsttime); 
     3940        } 
     3941 
     3942        return FALSE; 
     3943} 
     3944 
     3945/* 
     3946 * Set "lazy-movement" delay 
     3947 */ 
     3948static void do_cmd_lazymove_delay(void) 
     3949{ 
     3950        bool res; 
     3951        char tmp[4] = ""; 
     3952 
     3953        strnfmt(tmp, sizeof(tmp), "%i", lazymove_delay); 
     3954 
     3955        /* Prompt */ 
     3956        prt("Command: Movement Delay Factor", 20, 0); 
     3957 
     3958        prt(format("Current movement delay: %d (%d msec)", 
     3959                           lazymove_delay, lazymove_delay * 10), 22, 0); 
     3960        prt("New movement delay: ", 21, 0); 
     3961 
     3962        /* Ask the user for a string */ 
     3963        res = askfor_aux(tmp, sizeof(tmp), askfor_aux_numbers); 
     3964 
     3965        /* Process input */ 
     3966        if (res) 
     3967        { 
     3968                lazymove_delay = (u16b) strtoul(tmp, NULL, 0); 
     3969        } 
     3970} 
     3971 
     3972 
     3973 
    39183974/* 
    39193975 * Ask for a "user pref file" and process it. 
     
    39864042        {'d', "Set base delay factor", (action_f) do_cmd_delay, 0},  
    39874043        {'h', "Set hitpoint warning", (action_f) do_cmd_hp_warn, 0},  
    3988         {0, 0, 0, 0}, /* Special choices */ 
     4044        {'i', "Set movement delay", (action_f) do_cmd_lazymove_delay, 0},  
    39894045        {'l', "Load a user pref file", (action_f) do_cmd_pref_file_hack, (void*)20}, 
    39904046        {'o', "Dump options", do_dump_options, 0},  
  • trunk/src/defines.h

    r789 r816  
    26512651 
    26522652#endif /* !INCLUDED_DEFINES_H */ 
     2653 
     2654 
     2655#define SCAN_INSTANT ((u32b) -1) 
     2656#define SCAN_OFF 0 
     2657#define SCAN_MACRO 45 
  • trunk/src/dungeon.c

    r815 r816  
    10871087        { 
    10881088                /* Do not wait */ 
    1089                 inkey_scan = TRUE
     1089                inkey_scan = SCAN_INSTANT
    10901090 
    10911091                /* Check for a key */ 
  • trunk/src/externs.h

    r815 r816  
    116116extern bool inkey_base; 
    117117extern bool inkey_xtra; 
    118 extern bool inkey_scan; 
     118extern u32b inkey_scan; 
    119119extern bool inkey_flag; 
    120120extern s16b coin_type; 
     
    696696 
    697697#endif /* !INCLUDED_EXTERNS_H */ 
     698 
     699 
     700extern u16b lazymove_delay; 
  • trunk/src/load.c

    r789 r816  
    882882        op_ptr->hitpoint_warn = b; 
    883883 
    884         /* Old cheating options */ 
     884        /* Read lazy movement delay */ 
    885885        rd_u16b(&tmp16u); 
     886        lazymove_delay = (tmp16u < 1000) ? tmp16u : 0; 
    886887 
    887888 
  • trunk/src/save.c

    r789 r816  
    322322        wr_byte(op_ptr->hitpoint_warn); 
    323323 
    324         wr_u16b(0);     /* oops */ 
     324        /* Write movement delay */ 
     325        wr_u16b(lazymove_delay); 
    325326 
    326327 
  • trunk/src/util.c

    r815 r816  
    790790 * known not to be that macro trigger.  XXX XXX XXX 
    791791 */ 
    792 static ui_event_data inkey_aux(void
     792static ui_event_data inkey_aux(int scan_cutoff
    793793{ 
    794794        int k = 0, n, p = 0, w = 0; 
     
    800800         
    801801        char buf[1024]; 
    802          
     802 
    803803        /* Initialize the no return */ 
    804         ke0.type = EVT_KBRD
     804        ke0.type = EVT_NONE
    805805        ke0.key = 0; 
    806806        ke0.index = 0; /* To fix GCC warnings on X11 */ 
     
    809809  
    810810        /* Wait for a keypress */ 
    811         (void)(Term_inkey(&ke, TRUE, TRUE)); 
    812         ch = ke.key; 
     811        if (scan_cutoff == SCAN_OFF) 
     812        { 
     813                (void)(Term_inkey(&ke, TRUE, TRUE)); 
     814                ch = ke.key; 
     815        } 
     816        else 
     817        { 
     818                w = 0; 
     819 
     820                /* Wait only as long as macro activation would wait*/ 
     821                while (Term_inkey(&ke, FALSE, TRUE) != 0) 
     822                { 
     823                        /* Increase "wait" */ 
     824                        w++; 
     825 
     826                        /* Excessive delay */ 
     827                        if (w >= scan_cutoff) 
     828                        { 
     829                                ke0.type = EVT_KBRD; 
     830                                return ke0; 
     831                        } 
     832 
     833                        /* Delay */ 
     834                        Term_xtra(TERM_XTRA_DELAY, 10); 
     835                } 
     836                ch = ke.key; 
     837        } 
     838 
    813839         
    814840        /* End "macro action" */ 
     
    862888                { 
    863889                        /* Increase "wait" */ 
    864                         w += 10
     890                        w ++
    865891                 
    866892                        /* Excessive delay */ 
    867                         if (w >= 100) break; 
     893                        if (w >= SCAN_MACRO) break; 
    868894                 
    869895                        /* Delay */ 
    870                         Term_xtra(TERM_XTRA_DELAY, w); 
     896                        Term_xtra(TERM_XTRA_DELAY, 10); 
    871897                } 
    872898        } 
     
    10401066        /* Initialise keypress */ 
    10411067        ke.key = 0; 
    1042         ke.type = EVT_KBRD
     1068        ke.type = EVT_NONE
    10431069         
    10441070        /* Hack -- Use the "inkey_next" pointer */ 
     
    10471073                /* Get next character, and advance */ 
    10481074                ke.key = *inkey_next++; 
     1075                ke.type = EVT_KBRD; 
    10491076                 
    10501077                /* Cancel the various "global parameters" */ 
     
    10801107                /* End "macro action" */ 
    10811108                parse_macro = FALSE; 
    1082                 ke.type = EVT_KBRD; 
    10831109                 
    10841110                /* End "macro trigger" */ 
     
    11061132         
    11071133        /* Get a key */ 
    1108         while (!ke.key
    1109         { 
    1110                 /* Hack -- Handle "inkey_scan" */ 
    1111                 if (!inkey_base && inkey_scan && 
     1134        while (ke.type == EVT_NONE
     1135        { 
     1136                /* Hack -- Handle "inkey_scan == SCAN_INSTANT */ 
     1137                if (!inkey_base && inkey_scan == SCAN_INSTANT && 
    11121138                   (0 != Term_inkey(&kk, FALSE, FALSE))) 
    11131139                { 
     1140                        ke.type = EVT_KBRD; 
    11141141                        break; 
    11151142                } 
     
    11521179                                { 
    11531180                                        /* Done */ 
     1181                                        ke.type = EVT_KBRD; 
    11541182                                        break; 
    11551183                                } 
     
    11661194                                { 
    11671195                                        /* Done */ 
     1196                                        ke.type = EVT_KBRD; 
    11681197                                        break; 
    11691198                                } 
     
    11731202                                { 
    11741203                                        /* Increase "wait" */ 
    1175                                         w += 10
     1204                                        w ++
    11761205 
    11771206                                        /* Excessive delay */ 
    1178                                         if (w >= 100) break; 
     1207                                        if (w >= SCAN_MACRO) break; 
    11791208 
    11801209                                        /* Delay */ 
    1181                                         Term_xtra(TERM_XTRA_DELAY, w); 
     1210                                        Term_xtra(TERM_XTRA_DELAY, 10); 
    11821211 
    11831212                                } 
     
    11901219 
    11911220                /* Get a key (see above) */ 
    1192                 ke = inkey_aux(); 
     1221                ke = inkey_aux(inkey_scan); 
    11931222 
    11941223                /* Handle mouse buttons */ 
     
    12181247                { 
    12191248                        /* Strip this key */ 
    1220                         ke.key = 0
     1249                        ke.type = EVT_NONE
    12211250 
    12221251                        /* Continue */ 
     
    12301259                 
    12311260                /* End "macro trigger" */ 
    1232                 if (parse_under && (ke.key <= 32)) 
     1261                if (parse_under && (ke.key >=0 && ke.key <= 32)) 
    12331262                { 
    12341263                        /* Strip this key */ 
     1264                        ke.type = EVT_NONE; 
    12351265                        ke.key = 0; 
    12361266                 
     
    12431273                { 
    12441274                        /* Strip this key */ 
     1275                        ke.type = EVT_NONE; 
    12451276                        ke.key = 0; 
    12461277                } 
     
    12501281                { 
    12511282                        /* Strip this key */ 
     1283                        ke.type = EVT_NONE; 
    12521284                        ke.key = 0; 
    12531285 
     
    12601292                { 
    12611293                        /* Strip this key */ 
     1294                        ke.type = EVT_NONE; 
    12621295                        ke.key = 0; 
    12631296                } 
     
    28312864                } 
    28322865 
    2833  
    28342866                /* Special case for the arrow keys */ 
    28352867                if (isarrow(ke.key)) 
     
    28432875                        } 
    28442876                } 
    2845  
    28462877 
    28472878                /* Allow "keymaps" to be bypassed */ 
  • trunk/src/variable.c

    r670 r816  
    103103bool inkey_base;                /* See the "inkey()" function */ 
    104104bool inkey_xtra;                /* See the "inkey()" function */ 
    105 bool inkey_scan;              /* See the "inkey()" function */ 
     105u32b inkey_scan;              /* See the "inkey()" function */ 
    106106bool inkey_flag;                /* See the "inkey()" function */ 
    107107 
     
    786786bool new_save; 
    787787 
     788 
     789/* Delay in centiseconds before moving to allow another keypress */ 
     790/* Zero means normal instant movement. */ 
     791u16b lazymove_delay = 0; 
  • trunk/src/wizard.c

    r793 r816  
    734734                        { 
    735735                                /* Do not wait */ 
    736                                 inkey_scan = TRUE
     736                                inkey_scan = SCAN_INSTANT
    737737 
    738738                                /* Allow interupt */ 
  • trunk/src/xtra2.c

    r789 r816  
    18901890 
    18911891 
     1892int dir_transitions[10][10] =  
     1893{ 
     1894        /* 0-> */ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 
     1895        /* 1-> */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 
     1896        /* 2-> */ { 0, 0, 2, 0, 1, 0, 3, 0, 5, 0 },  
     1897        /* 3-> */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 
     1898        /* 4-> */ { 0, 0, 1, 0, 4, 0, 5, 0, 7, 0 },  
     1899        /* 5-> */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 
     1900        /* 6-> */ { 0, 0, 3, 0, 5, 0, 6, 0, 9, 0 },  
     1901        /* 7-> */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 
     1902        /* 8-> */ { 0, 0, 5, 0, 7, 0, 9, 0, 8, 0 },  
     1903        /* 9-> */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 
     1904}; 
     1905 
    18921906 
    18931907/* 
     
    19841998                        default: 
    19851999                        { 
    1986                                 dir = target_dir(ke.key); 
    1987                                 break; 
     2000                                int keypresses_handled = 0; 
     2001                                 
     2002                                while (ke.key != 0) 
     2003                                { 
     2004                                        int this_dir; 
     2005                                         
     2006                                        /* XXX Ideally show and move the cursor here to indicate  
     2007                                           the currently "Pending" direction. XXX */ 
     2008                                        this_dir = target_dir(ke.key); 
     2009                                         
     2010                                        if (this_dir) 
     2011                                        { 
     2012                                                dir = dir_transitions[dir][this_dir]; 
     2013                                        } 
     2014                                        else 
     2015                                        { 
     2016                                                break; 
     2017                                        } 
     2018                                         
     2019                                        if (lazymove_delay == 0 || ++keypresses_handled > 1) 
     2020                                                break; 
     2021                                 
     2022                                        /* See if there's a second keypress within the defined 
     2023                                           period of time. */ 
     2024                                        inkey_scan = lazymove_delay;  
     2025                                        ke = inkey_ex(); 
     2026                                } 
    19882027                        } 
    19892028                } 
     
    20212060        return (TRUE); 
    20222061} 
    2023  
    20242062 
    20252063 
     
    20452083        ui_event_data ke; 
    20462084 
    2047         cptr p; 
    2048  
    20492085        if (repeat_pull(dp)) 
    20502086        { 
     
    20612097        while (!dir) 
    20622098        { 
    2063                 /* Choose a prompt */ 
    2064                 p = "Direction or <click> (Escape to cancel)? "; 
    2065  
    2066                 /* Get a command (or Cancel) */ 
    2067                 if (!get_com_ex(p, &ke)) break; 
     2099                /* Paranoia XXX XXX XXX */ 
     2100                message_flush(); 
     2101 
     2102                /* Get first keypress - the first test is to avoid displaying the 
     2103                   prompt for direction if there's already a keypress queued up 
     2104                   and waiting - this just avoids a flickering prompt if there is 
     2105                   a "lazy" movement delay. */ 
     2106                inkey_scan = SCAN_INSTANT; 
     2107                ke = inkey_ex(); 
     2108                inkey_scan = SCAN_OFF; 
     2109 
     2110                if (ke.key != '\xff' && target_dir(ke.key) == 0) 
     2111                { 
     2112                        prt("Direction or <click> (Escape to cancel)? ", 0, 0); 
     2113                        ke = inkey_ex(); 
     2114                } 
    20682115 
    20692116                /* Check mouse coordinates */ 
     
    20892136                                else dir = 6; 
    20902137                        } 
    2091                         /* else continue; */ 
    2092                 } 
    2093  
    2094                 /* Convert keypress into a direction */ 
    2095                 else dir = target_dir(ke.key); 
     2138                } 
     2139 
     2140                /* Get other keypresses until a direction is chosen. */ 
     2141                else  
     2142                { 
     2143                        int keypresses_handled = 0; 
     2144 
     2145                        while (ke.key != 0) 
     2146                        { 
     2147                                int this_dir; 
     2148 
     2149                                if (ke.key == ESCAPE)  
     2150                                { 
     2151                                        /* Clear the prompt */ 
     2152                                        prt("", 0, 0); 
     2153 
     2154                                        return (FALSE); 
     2155                                } 
     2156 
     2157                                /* XXX Ideally show and move the cursor here to indicate  
     2158                                   the currently "Pending" direction. XXX */ 
     2159                                this_dir = target_dir(ke.key); 
     2160 
     2161                                if (this_dir) 
     2162                                { 
     2163                                        dir = dir_transitions[dir][this_dir]; 
     2164                                } 
     2165 
     2166                                if (lazymove_delay == 0 || ++keypresses_handled > 1) 
     2167                                        break; 
     2168 
     2169                                inkey_scan = lazymove_delay;  
     2170                                ke = inkey_ex(); 
     2171                        } 
     2172 
     2173                        /* 5 is equivalent to "escape" */ 
     2174                        if (dir == 5) 
     2175                        { 
     2176                                /* Clear the prompt */ 
     2177                                prt("", 0, 0); 
     2178 
     2179                                return (FALSE); 
     2180                        } 
     2181                } 
    20962182 
    20972183                /* Oops */ 
     
    20992185        } 
    21002186 
     2187        /* Clear the prompt */ 
     2188        prt("", 0, 0); 
     2189 
    21012190        /* Aborted */ 
    21022191        if (!dir) return (FALSE);