Added the sleep console command that waits for a specified amount of time.

Note that this isn't a GIB-specific command but is very useful in GIB
threads.  Fixed the range GIB command to respect the ifs local variable.
This commit is contained in:
Brian Koropoff 2002-10-13 19:46:47 +00:00
parent 70c1fee4c9
commit 72e1ab0c57
4 changed files with 26 additions and 1 deletions

View file

@ -59,6 +59,8 @@ typedef struct cbuf_s {
CBUF_STATE_STACK, // A buffer has been added to the stack
} state;
double resumetime; // Time when stack can be executed again
void *data; // Pointer to a custom structure if needed
} cbuf_t;

View file

@ -166,6 +166,12 @@ Cbuf_Execute_Stack (cbuf_t *cbuf)
{
cbuf_t *sp;
if (cbuf->resumetime) {
if (cbuf->resumetime < Sys_DoubleTime())
cbuf->resumetime = 0;
else
return;
}
for (sp = cbuf; sp->down; sp = sp->down);
while (sp) {
if (sp->down) {

View file

@ -520,6 +520,19 @@ Cmd_Wait_f (void)
cbuf_active->state = CBUF_STATE_WAIT;
}
/* Pauses execution for a specified number
of seconds */
void
Cmd_Sleep_f (void)
{
double waittime;
cbuf_t *p;
cbuf_active->state = CBUF_STATE_WAIT;
waittime = atof (Cmd_Argv (1));
for (p = cbuf_active; p->up; p = p->up); // Get to top of stack
p->resumetime = Sys_DoubleTime() + waittime;
}
void
Cmd_StuffCmds (cbuf_t *cbuf)
{
@ -592,6 +605,7 @@ Cmd_Init (void)
Cmd_AddCommand ("exec", Cmd_Exec_f, "Execute a script file");
Cmd_AddCommand ("echo", Cmd_Echo_f, "Print text to console");
Cmd_AddCommand ("wait", Cmd_Wait_f, "Wait a game tic");
Cmd_AddCommand ("sleep", Cmd_Sleep_f, "Wait for a certain number of seconds.");
cmd_warncmd = Cvar_Get ("cmd_warncmd", "0", CVAR_NONE, NULL, "Toggles the "
"display of error messages for unknown commands");
cmd_cbuf = Cbuf_New (&id_interp);

View file

@ -651,6 +651,7 @@ GIB_Range_f (void)
{
double i, inc, start, limit;
dstring_t *dstr;
const char *ifs;
if (GIB_Argc () < 3 || GIB_Argc () > 4) {
Cbuf_Error ("syntax",
"range: invalid syntax\n"
@ -668,9 +669,11 @@ GIB_Range_f (void)
GIB_Return ("");
return;
}
if (!(ifs = GIB_Var_Get_Local (cbuf_active, "ifs")))
ifs = " ";
dstr = dstring_newstr ();
for (i = atof(GIB_Argv(1)); inc < 0 ? i >= limit : i <= limit; i += inc)
dstring_appendstr (dstr, va(" %.10g", i));
dstring_appendstr (dstr, va("%s%.10g", ifs, i));
GIB_Return (dstr->str[0] ? dstr->str+1 : "");
dstring_delete (dstr);
}