mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
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:
parent
70c1fee4c9
commit
72e1ab0c57
4 changed files with 26 additions and 1 deletions
|
@ -59,6 +59,8 @@ typedef struct cbuf_s {
|
||||||
CBUF_STATE_STACK, // A buffer has been added to the stack
|
CBUF_STATE_STACK, // A buffer has been added to the stack
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
|
double resumetime; // Time when stack can be executed again
|
||||||
|
|
||||||
void *data; // Pointer to a custom structure if needed
|
void *data; // Pointer to a custom structure if needed
|
||||||
} cbuf_t;
|
} cbuf_t;
|
||||||
|
|
||||||
|
|
|
@ -166,6 +166,12 @@ Cbuf_Execute_Stack (cbuf_t *cbuf)
|
||||||
{
|
{
|
||||||
cbuf_t *sp;
|
cbuf_t *sp;
|
||||||
|
|
||||||
|
if (cbuf->resumetime) {
|
||||||
|
if (cbuf->resumetime < Sys_DoubleTime())
|
||||||
|
cbuf->resumetime = 0;
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (sp = cbuf; sp->down; sp = sp->down);
|
for (sp = cbuf; sp->down; sp = sp->down);
|
||||||
while (sp) {
|
while (sp) {
|
||||||
if (sp->down) {
|
if (sp->down) {
|
||||||
|
|
|
@ -520,6 +520,19 @@ Cmd_Wait_f (void)
|
||||||
cbuf_active->state = CBUF_STATE_WAIT;
|
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
|
void
|
||||||
Cmd_StuffCmds (cbuf_t *cbuf)
|
Cmd_StuffCmds (cbuf_t *cbuf)
|
||||||
{
|
{
|
||||||
|
@ -592,6 +605,7 @@ Cmd_Init (void)
|
||||||
Cmd_AddCommand ("exec", Cmd_Exec_f, "Execute a script file");
|
Cmd_AddCommand ("exec", Cmd_Exec_f, "Execute a script file");
|
||||||
Cmd_AddCommand ("echo", Cmd_Echo_f, "Print text to console");
|
Cmd_AddCommand ("echo", Cmd_Echo_f, "Print text to console");
|
||||||
Cmd_AddCommand ("wait", Cmd_Wait_f, "Wait a game tic");
|
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 "
|
cmd_warncmd = Cvar_Get ("cmd_warncmd", "0", CVAR_NONE, NULL, "Toggles the "
|
||||||
"display of error messages for unknown commands");
|
"display of error messages for unknown commands");
|
||||||
cmd_cbuf = Cbuf_New (&id_interp);
|
cmd_cbuf = Cbuf_New (&id_interp);
|
||||||
|
|
|
@ -651,6 +651,7 @@ GIB_Range_f (void)
|
||||||
{
|
{
|
||||||
double i, inc, start, limit;
|
double i, inc, start, limit;
|
||||||
dstring_t *dstr;
|
dstring_t *dstr;
|
||||||
|
const char *ifs;
|
||||||
if (GIB_Argc () < 3 || GIB_Argc () > 4) {
|
if (GIB_Argc () < 3 || GIB_Argc () > 4) {
|
||||||
Cbuf_Error ("syntax",
|
Cbuf_Error ("syntax",
|
||||||
"range: invalid syntax\n"
|
"range: invalid syntax\n"
|
||||||
|
@ -668,9 +669,11 @@ GIB_Range_f (void)
|
||||||
GIB_Return ("");
|
GIB_Return ("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!(ifs = GIB_Var_Get_Local (cbuf_active, "ifs")))
|
||||||
|
ifs = " ";
|
||||||
dstr = dstring_newstr ();
|
dstr = dstring_newstr ();
|
||||||
for (i = atof(GIB_Argv(1)); inc < 0 ? i >= limit : i <= limit; i += inc)
|
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 : "");
|
GIB_Return (dstr->str[0] ? dstr->str+1 : "");
|
||||||
dstring_delete (dstr);
|
dstring_delete (dstr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue