diff -Naur undeadzy-ioquake3_mirror/code/qcommon/cmd.c ioquake3_mirror-c6bc843-delaypatch/code/qcommon/cmd.c --- undeadzy-ioquake3_mirror/code/qcommon/cmd.c 2012-03-23 20:38:26 +0000 +++ ioquake3_mirror-c6bc843-delaypatch/code/qcommon/cmd.c 2012-03-17 19:23:50 +0000 @@ -38,6 +38,29 @@ byte cmd_text_buf[MAX_CMD_BUFFER]; +// Delay stuff + +#define MAX_DELAYED_COMMANDS 64 +#define CMD_DELAY_FRAME_FIRE 1 +#define CMD_DELAY_UNUSED 0 + +typedef enum +{ + CMD_DELAY_MSEC, + CMD_DELAY_FRAME +} cmdDelayType_t; + +typedef struct +{ + char name[MAX_CMD_LINE]; + char text[MAX_CMD_LINE]; + int delay; + cmdDelayType_t type; +} delayed_cmd_s; + +delayed_cmd_s delayed_cmd[MAX_DELAYED_COMMANDS]; + + //============================================================================= /* @@ -253,6 +276,52 @@ /* ============================================================================== + COMMANDS DELAYING + +============================================================================== +*/ + +/* +=============== +Cdelay_Frame +=============== +*/ + +void Cdelay_Frame( void ) { + int i; + int sys_time = Sys_Milliseconds(); + qboolean run_it; + + for(i=0; (i (command)\nremoves all commands with in them.\nif (command) is specified, the removal will be limited only to delays whose commands contain (command).\n"); + return; + } + + find = Cmd_Argv(1); + limit = Cmd_Argv(2); + + for(i=0; (i \ndelay f \nexecutes after the delay\n"); + return; + } + + raw_delay = Cmd_Argv(1); + if(!isdigit(raw_delay[0])) + { + name = raw_delay; + raw_delay = Cmd_Argv(2); + cmd = Cmd_ArgsFrom(3); + } + else + { + name = ""; + cmd = Cmd_ArgsFrom(2); + } + delay = atoi(raw_delay); + + if(delay < 1) + { + Com_Printf ("delay: the delay must be a positive integer"); + return; + } + + //search for an unused slot + for(i=0; (i args ) + Field_CompleteCommand( p, qtrue, qtrue ); + } +} + +/* +================== +Cmd_CompleteUnDelay +================== +*/ +void Cmd_CompleteUnDelay( char *args, int argNum ) { + if( argNum == 2 ) { + Field_CompleteDelay( ); + } +} + +/* ============ Cmd_Init ============ @@ -858,4 +1092,9 @@ Cmd_SetCommandCompletionFunc( "vstr", Cvar_CompleteCvarName ); Cmd_AddCommand ("echo",Cmd_Echo_f); Cmd_AddCommand ("wait", Cmd_Wait_f); + Cmd_AddCommand ("delay", Cmd_Delay_f); + Cmd_SetCommandCompletionFunc( "delay", Cmd_CompleteDelay ); + Cmd_AddCommand ("undelay", Cmd_Undelay_f); + Cmd_SetCommandCompletionFunc( "undelay", Cmd_CompleteUnDelay ); + Cmd_AddCommand ("undelayAll", Cmd_UndelayAll_f); } diff -Naur undeadzy-ioquake3_mirror/code/qcommon/common.c ioquake3_mirror-c6bc843-delaypatch/code/qcommon/common.c --- undeadzy-ioquake3_mirror/code/qcommon/common.c 2012-03-23 20:38:30 +0000 +++ ioquake3_mirror-c6bc843-delaypatch/code/qcommon/common.c 2012-03-17 19:25:14 +0000 @@ -3136,6 +3136,7 @@ msec = com_frameTime - lastTime; Cbuf_Execute (); + Cdelay_Frame (); if (com_altivec->modified) { @@ -3434,6 +3435,22 @@ } /* +=============== +Field_CompleteDelay +=============== +*/ +void Field_CompleteDelay( void ) +{ + matchCount = 0; + shortestMatch[ 0 ] = 0; + + Cmd_DelayCompletion( FindMatches ); + + if( !Field_Complete( ) ) + Cmd_DelayCompletion( PrintMatches ); +} + +/* =============== Field_CompleteCommand =============== diff -Naur undeadzy-ioquake3_mirror/code/qcommon/qcommon.h ioquake3_mirror-c6bc843-delaypatch/code/qcommon/qcommon.h --- undeadzy-ioquake3_mirror/code/qcommon/qcommon.h 2012-03-23 20:38:49 +0000 +++ ioquake3_mirror-c6bc843-delaypatch/code/qcommon/qcommon.h 2012-03-17 19:27:38 +0000 @@ -415,6 +415,10 @@ // Normally called once per frame, but may be explicitly invoked. // Do not call inside a command function, or current args will be destroyed. +void Cdelay_Frame (void); +//Check if a delayed command have to be executed and decreases the remaining +//delay time for all of them + //=========================================================================== /* @@ -443,6 +447,7 @@ void Cmd_RemoveCommandSafe( const char *cmd_name ); void Cmd_CommandCompletion( void(*callback)(const char *s) ); +void Cmd_DelayCompletion( void(*callback)(const char *s) ); // callback with each valid string void Cmd_SetCommandCompletionFunc( const char *command, completionFunc_t complete ); @@ -762,6 +767,7 @@ void Field_CompleteKeyname( void ); void Field_CompleteFilename( const char *dir, const char *ext, qboolean stripExt, qboolean allowNonPureFilesOnDisk ); +void Field_CompleteDelay( void ); void Field_CompleteCommand( char *cmd, qboolean doCommands, qboolean doCvars ); diff -Naur undeadzy-ioquake3_mirror/code/ui/ui_shared.c ioquake3_mirror-c6bc843-delaypatch/code/ui/ui_shared.c --- undeadzy-ioquake3_mirror/code/ui/ui_shared.c 2012-03-23 20:39:13 +0000 +++ ioquake3_mirror-c6bc843-delaypatch/code/ui/ui_shared.c 2012-03-17 20:44:00 +0000 @@ -42,6 +42,17 @@ static scrollInfo_t scrollInfo; +#define MAX_DELAYED_COMMANDS 64 + +typedef struct delayed_cmd_s +{ + itemDef_t *item; + int time; +} +delayed_cmd_t; + +delayed_cmd_t delayed_cmd[ MAX_DELAYED_COMMANDS ]; + static void (*captureFunc) (void *p) = 0; static void *captureData = NULL; static itemDef_t *itemCapture = NULL; // item that has the mouse captured ( if any ) @@ -1234,6 +1245,43 @@ } } +void Menu_DelayItemByName( menuDef_t *menu, const char *p, int time ) +{ + itemDef_t *item; + int i, j = 0; + int count = Menu_ItemsMatchingGroup( menu, p ); + + for( i = 0; i < count; i++ ) + { + item = Menu_GetMatchingItemByNumber( menu, i, p ); + + if( item != NULL && item->delayEvent && item->delayEvent[ 0 ] ) + { + for( ; j < MAX_DELAYED_COMMANDS; j++ ) + { + if( !delayed_cmd[ j ].time ) + { + delayed_cmd[ j ].item = item; + delayed_cmd[ j ].time = DC->realTime + time; + j++; + break; + } + } + } + } +} + +void Script_Delay( itemDef_t *item, char **args ) +{ + const char *name; + int time; + + if( Int_Parse( args, &time ) && String_Parse( args, &name ) ) + { + Menu_DelayItemByName( item->parent, name, time ); + } +} + commandDef_t commandList[] = { @@ -1257,7 +1305,8 @@ {"exec", &Script_Exec}, // group/name {"play", &Script_Play}, // group/name {"playlooped", &Script_playLooped}, // group/name - {"orbit", &Script_Orbit} // group/name + {"orbit", &Script_Orbit}, // group/name + {"delay", &Script_Delay}, // group/name }; int scriptCommandCount = ARRAY_LEN(commandList); @@ -3839,6 +3888,14 @@ return; } + // check for delays + for( i = 0; i < MAX_DELAYED_COMMANDS; i++ ) { + if( delayed_cmd[ i ].item == item && delayed_cmd[ i ].time && delayed_cmd[ i ].time < DC->realTime ) { + Item_RunScript( item, item->delayEvent ); + delayed_cmd[ i ].time = 0; + } + } + if (item->window.flags & WINDOW_ORBITING) { if (DC->realTime > item->window.nextTime) { float rx, ry, a, c, s, w, h; @@ -4800,6 +4857,14 @@ return qtrue; } +qboolean ItemParse_delayEvent( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->delayEvent ) ) + return qfalse; + + return qtrue; +} + qboolean ItemParse_action( itemDef_t *item, int handle ) { if (!PC_Script_Parse(handle, &item->action)) { return qfalse; @@ -5085,6 +5150,7 @@ {"mouseExit", ItemParse_mouseExit, NULL}, {"mouseEnterText", ItemParse_mouseEnterText, NULL}, {"mouseExitText", ItemParse_mouseExitText, NULL}, + {"delayEvent", ItemParse_delayEvent, NULL}, {"action", ItemParse_action, NULL}, {"special", ItemParse_special, NULL}, {"cvar", ItemParse_cvar, NULL}, diff -Naur undeadzy-ioquake3_mirror/code/ui/ui_shared.h ioquake3_mirror-c6bc843-delaypatch/code/ui/ui_shared.h --- undeadzy-ioquake3_mirror/code/ui/ui_shared.h 2012-03-23 20:39:10 +0000 +++ ioquake3_mirror-c6bc843-delaypatch/code/ui/ui_shared.h 2012-03-17 20:04:20 +0000 @@ -235,6 +235,7 @@ const char *mouseExitText; // mouse exit script const char *mouseEnter; // mouse enter script const char *mouseExit; // mouse exit script + const char *delayEvent; // delay event script const char *action; // select script const char *onFocus; // select script const char *leaveFocus; // select script