Command repeating by using cmd queues

This replaces the old pushq/saveq arrays (which were used to save
the keys pressed by the user for repeating a previous command)
with a new command queue.  This means there's no hard-coded limit
to the saved keys, and it can repeat extended commands which are
not bound to any key.
This commit is contained in:
Pasi Kallinen
2022-08-08 14:02:59 +03:00
parent 4e6d3aba4f
commit fd9745f9c6
34 changed files with 417 additions and 379 deletions

View File

@@ -658,7 +658,6 @@ struct _create_particular_data {
};
/* some array sizes for 'g' */
#define BSIZE 20
#define WIZKIT_MAX 128
#define CVT_BUF_SIZE 64
@@ -677,12 +676,14 @@ enum cmdq_cmdtypes {
CMDQ_EXTCMD, /* extended command, cmdq_add_ec() */
CMDQ_DIR, /* direction, cmdq_add_dir() */
CMDQ_USER_INPUT, /* placeholder for user input, cmdq_add_userinput() */
CMDQ_INT, /* integer value, cmdq_add_int() */
};
struct _cmd_queue {
int typ;
char key;
schar dirx, diry, dirz;
int intval;
const struct ext_func_tab *ec_entry;
struct _cmd_queue *next;
};
@@ -694,6 +695,12 @@ struct enum_dump {
typedef long cmdcount_nht; /* Command counts */
enum {
CQ_CANNED = 0, /* internal canned sequence */
CQ_REPEAT, /* user-inputted, if g.in_doagain, replayed */
NUM_CQS
};
/*
* 'g' -- instance_globals holds engine state that does not need to be
* persisted upon game exit. The initialization state is well defined
@@ -706,7 +713,7 @@ typedef long cmdcount_nht; /* Command counts */
*/
struct instance_globals {
struct _cmd_queue *command_queue;
struct _cmd_queue *command_queue[NUM_CQS];
/* apply.c */
int jumping_is_magic; /* current jump result of magic */
@@ -740,12 +747,6 @@ struct instance_globals {
which requires a thing and a direction), and the input prompt is
not shown. Also, while in_doagain is TRUE, no keystrokes can be
saved into the saveq. */
char pushq[BSIZE];
char saveq[BSIZE];
int phead;
int ptail;
int shead;
int stail;
coord clicklook_cc;
winid en_win;
boolean en_via_menu;

View File

@@ -251,17 +251,18 @@ extern boolean redraw_cmd(char);
extern const char *levltyp_to_name(int);
extern void reset_occupations(void);
extern void set_occupation(int(*)(void), const char *, cmdcount_nht);
extern void cmdq_add_ec(int(*)(void));
extern void cmdq_add_key(char);
extern void cmdq_add_dir(schar, schar, schar);
extern void cmdq_add_userinput(void);
extern void cmdq_add_ec(int, int(*)(void));
extern void cmdq_add_key(int, char);
extern void cmdq_add_dir(int, schar, schar, schar);
extern void cmdq_add_userinput(int);
extern void cmdq_add_int(int, int);
extern void cmdq_shift(int);
extern struct _cmd_queue *cmdq_reverse(struct _cmd_queue *);
extern struct _cmd_queue *cmdq_copy(int);
extern struct _cmd_queue *cmdq_pop(void);
extern struct _cmd_queue *cmdq_peek(void);
extern void cmdq_clear(void);
extern struct _cmd_queue *cmdq_peek(int);
extern void cmdq_clear(int);
extern char pgetchar(void);
extern void pushch(char);
extern void savech(char);
extern void savech_extcmd(const char *, boolean);
extern char extcmd_initiator(void);
extern int doextcmd(void);
extern struct ext_func_tab *extcmds_getentry(int);
@@ -300,7 +301,7 @@ extern char readchar(void);
extern char readchar_poskey(coordxy *, coordxy *, int *);
extern void sanity_check(void);
extern char* key2txt(uchar, char *);
extern char yn_function(const char *, const char *, char);
extern char yn_function(const char *, const char *, char, boolean);
extern boolean paranoid_query(boolean, const char *);
extern void makemap_prepost(boolean, boolean);

View File

@@ -443,12 +443,12 @@ typedef uint32_t mmflags_nht; /* makemon MM_ flags */
#define MMOVE_NOMOVES 4 /* monster has no valid locations to move to */
/*** some utility macros ***/
#define yn(query) yn_function(query, ynchars, 'n')
#define ynq(query) yn_function(query, ynqchars, 'q')
#define ynaq(query) yn_function(query, ynaqchars, 'y')
#define nyaq(query) yn_function(query, ynaqchars, 'n')
#define nyNaq(query) yn_function(query, ynNaqchars, 'n')
#define ynNaq(query) yn_function(query, ynNaqchars, 'y')
#define yn(query) yn_function(query, ynchars, 'n', TRUE)
#define ynq(query) yn_function(query, ynqchars, 'q', TRUE)
#define ynaq(query) yn_function(query, ynaqchars, 'y', TRUE)
#define nyaq(query) yn_function(query, ynaqchars, 'n', TRUE)
#define nyNaq(query) yn_function(query, ynNaqchars, 'n', TRUE)
#define ynNaq(query) yn_function(query, ynNaqchars, 'y', TRUE)
/* Macros for scatter */
#define VIS_EFFECTS 0x01 /* display visual effects */