Skip to content

Commit

Permalink
Command repeating by using cmd queues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paxed committed Aug 9, 2022
1 parent 4e6d3ab commit fd9745f
Show file tree
Hide file tree
Showing 34 changed files with 417 additions and 379 deletions.
17 changes: 9 additions & 8 deletions include/decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
};
Expand All @@ -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
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 11 additions & 10 deletions include/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions include/hack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 4 additions & 5 deletions src/allmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ moveloop_core(void)
check_leash(old_ux, old_uy);
}
/* clear doagain keystrokes */
pushch(0);
savech(0);
cmdq_clear(CQ_CANNED);
cmdq_clear(CQ_REPEAT);
}
}
/* delayed change may not be valid anymore */
Expand Down Expand Up @@ -431,7 +431,7 @@ moveloop_core(void)
if ((ch = pgetchar()) == ABORT)
mvl_abort_lev++;
else
pushch(ch);
cmdq_push_key(CQ_CANNED, ch);
}
if (!mvl_abort_lev && (*g.occupation)() == 0)
#else
Expand Down Expand Up @@ -609,11 +609,10 @@ stop_occupation(void)
g.occupation = 0;
g.context.botl = TRUE; /* in case u.uhs changed */
nomul(0);
pushch(0);
} else if (g.multi >= 0) {
nomul(0);
}
cmdq_clear();
cmdq_clear(CQ_CANNED);
}

void
Expand Down
16 changes: 8 additions & 8 deletions src/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -1721,8 +1721,8 @@ dorub(void)
}
if (obj != uwep) {
if (wield_tool(obj, "rub")) {
cmdq_add_ec(dorub);
cmdq_add_key(obj->invlet);
cmdq_add_ec(CQ_CANNED, dorub);
cmdq_add_key(CQ_CANNED, obj->invlet);
return ECMD_TIME;
}
return ECMD_OK;
Expand Down Expand Up @@ -2837,8 +2837,8 @@ use_whip(struct obj *obj)

if (obj != uwep) {
if (wield_tool(obj, "lash")) {
cmdq_add_ec(doapply);
cmdq_add_key(obj->invlet);
cmdq_add_ec(CQ_CANNED, doapply);
cmdq_add_key(CQ_CANNED, obj->invlet);
return ECMD_TIME;
}
return ECMD_OK;
Expand Down Expand Up @@ -3232,8 +3232,8 @@ use_pole(struct obj *obj, boolean autohit)
}
if (obj != uwep) {
if (wield_tool(obj, "swing")) {
cmdq_add_ec(doapply);
cmdq_add_key(obj->invlet);
cmdq_add_ec(CQ_CANNED, doapply);
cmdq_add_key(CQ_CANNED, obj->invlet);
return ECMD_TIME;
}
return ECMD_OK;
Expand Down Expand Up @@ -3509,8 +3509,8 @@ use_grapple(struct obj *obj)
}
if (obj != uwep) {
if (wield_tool(obj, "cast")) {
cmdq_add_ec(doapply);
cmdq_add_key(obj->invlet);
cmdq_add_ec(CQ_CANNED, doapply);
cmdq_add_key(CQ_CANNED, obj->invlet);
return ECMD_TIME;
}
return ECMD_OK;
Expand Down
Loading

0 comments on commit fd9745f

Please sign in to comment.