home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / framework / CmdSystem.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  9KB  |  186 lines

  1.  
  2. #ifndef __CMDSYSTEM_H__
  3. #define __CMDSYSTEM_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.     Console command execution and command text buffering.
  9.  
  10.     Any number of commands can be added in a frame from several different
  11.     sources. Most commands come from either key bindings or console line input,
  12.     but entire text files can be execed.
  13.  
  14.     Command execution takes a null terminated string, breaks it into tokens,
  15.     then searches for a command or variable that matches the first token.
  16.  
  17. ===============================================================================
  18. */
  19.  
  20. // command flags
  21. typedef enum {
  22.     CMD_FL_ALL                = -1,
  23.     CMD_FL_CHEAT            = BIT(0),    // command is considered a cheat
  24.     CMD_FL_SYSTEM            = BIT(1),    // system command
  25.     CMD_FL_RENDERER            = BIT(2),    // renderer command
  26.     CMD_FL_SOUND            = BIT(3),    // sound command
  27.     CMD_FL_GAME                = BIT(4),    // game command
  28.     CMD_FL_TOOL                = BIT(5)    // tool command
  29. } cmdFlags_t;
  30.  
  31. // parameters for command buffer stuffing
  32. typedef enum {
  33.     CMD_EXEC_NOW,                        // don't return until completed
  34.     CMD_EXEC_INSERT,                    // insert at current position, but don't run yet
  35.     CMD_EXEC_APPEND                        // add to end of the command buffer (normal case)
  36. } cmdExecution_t;
  37.  
  38. // command function
  39. typedef void (*cmdFunction_t)( const idCmdArgs &args );
  40.  
  41. // argument completion function
  42. typedef void (*argCompletion_t)( const idCmdArgs &args, void(*callback)( const char *s ) );
  43.  
  44.  
  45. class idCmdSystem {
  46. public:
  47.     virtual                ~idCmdSystem( void ) {}
  48.  
  49.     virtual void        Init( void ) = 0;
  50.     virtual void        Shutdown( void ) = 0;
  51.  
  52.                         // Registers a command and the function to call for it.
  53.     virtual void        AddCommand( const char *cmdName, cmdFunction_t function, int flags, const char *description, argCompletion_t argCompletion = NULL ) = 0;
  54.                         // Removes a command.
  55.     virtual void        RemoveCommand( const char *cmdName ) = 0;
  56.                         // Remove all commands with one of the flags set.
  57.     virtual void        RemoveFlaggedCommands( int flags ) = 0;
  58.  
  59.                         // Command and argument completion using callback for each valid string.
  60.     virtual void        CommandCompletion( void(*callback)( const char *s ) ) = 0;
  61.     virtual void        ArgCompletion( const char *cmdString, void(*callback)( const char *s ) ) = 0;
  62.  
  63.                         // Adds command text to the command buffer, does not add a final \n
  64.     virtual void        BufferCommandText( cmdExecution_t exec, const char *text ) = 0;
  65.                         // Pulls off \n \r or ; terminated lines of text from the command buffer and
  66.                         // executes the commands. Stops when the buffer is empty.
  67.                         // Normally called once per frame, but may be explicitly invoked.
  68.     virtual void        ExecuteCommandBuffer( void ) = 0;
  69.  
  70.                         // Base for path/file auto-completion.
  71.     virtual void        ArgCompletion_FolderExtension( const idCmdArgs &args, void(*callback)( const char *s ), const char *folder, bool stripFolder, ... ) = 0;
  72.                         // Base for decl name auto-completion.
  73.     virtual void        ArgCompletion_DeclName( const idCmdArgs &args, void(*callback)( const char *s ), int type ) = 0;
  74.  
  75.                         // Adds to the command buffer in tokenized form ( CMD_EXEC_NOW or CMD_EXEC_APPEND only )
  76.     virtual void        BufferCommandArgs( cmdExecution_t exec, const idCmdArgs &args ) = 0;
  77.  
  78.                         // Setup a reloadEngine to happen on next command run, and give a command to execute after reload
  79.     virtual void        SetupReloadEngine( const idCmdArgs &args ) = 0;
  80.     virtual bool        PostReloadEngine( void ) = 0;
  81.  
  82.                         // Default argument completion functions.
  83.     static void            ArgCompletion_Boolean( const idCmdArgs &args, void(*callback)( const char *s ) );
  84.     template<int min,int max>
  85.     static void            ArgCompletion_Integer( const idCmdArgs &args, void(*callback)( const char *s ) );
  86.     template<const char **strings>
  87.     static void            ArgCompletion_String( const idCmdArgs &args, void(*callback)( const char *s ) );
  88.     template<int type>
  89.     static void            ArgCompletion_Decl( const idCmdArgs &args, void(*callback)( const char *s ) );
  90.     static void            ArgCompletion_FileName( const idCmdArgs &args, void(*callback)( const char *s ) );
  91.  
  92. // RAVEN BEGIN
  93. // mekberg: added
  94.     static void            ArgCompletion_GuiName( const idCmdArgs &args, void(*callback)( const char *s ) );
  95. // RAVEN END
  96.  
  97.     static void            ArgCompletion_MapName( const idCmdArgs &args, void(*callback)( const char *s ) );
  98.     static void            ArgCompletion_ModelName( const idCmdArgs &args, void(*callback)( const char *s ) );
  99.     static void            ArgCompletion_SoundName( const idCmdArgs &args, void(*callback)( const char *s ) );
  100.     static void            ArgCompletion_ImageName( const idCmdArgs &args, void(*callback)( const char *s ) );
  101.     static void            ArgCompletion_VideoName( const idCmdArgs &args, void(*callback)( const char *s ) );
  102. //RAVEN BEGIN
  103. //nrausch: standalone video support
  104.     static void            ArgCompletion_StandaloneVideoName( const idCmdArgs &args, void(*callback)( const char *s ) );
  105. //RAVEN END
  106.     static void            ArgCompletion_ConfigName( const idCmdArgs &args, void(*callback)( const char *s ) );
  107.     static void            ArgCompletion_SaveGame( const idCmdArgs &args, void(*callback)( const char *s ) );
  108.     static void            ArgCompletion_DemoName( const idCmdArgs &args, void(*callback)( const char *s ) );
  109. };
  110.  
  111. extern idCmdSystem *    cmdSystem;
  112.  
  113.  
  114. ID_INLINE void idCmdSystem::ArgCompletion_Boolean( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  115.     callback( va( "%s 0", args.Argv( 0 ) ) );
  116.     callback( va( "%s 1", args.Argv( 0 ) ) );
  117. }
  118.  
  119. template<int min,int max> ID_STATIC_TEMPLATE ID_INLINE void idCmdSystem::ArgCompletion_Integer( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  120.     for ( int i = min; i <= max; i++ ) {
  121.         callback( va( "%s %d", args.Argv( 0 ), i ) );
  122.     }
  123. }
  124.  
  125. template<const char **strings> ID_STATIC_TEMPLATE ID_INLINE void idCmdSystem::ArgCompletion_String( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  126.     for ( int i = 0; strings[i]; i++ ) {
  127.         callback( va( "%s %s", args.Argv( 0 ), strings[i] ) );
  128.     }
  129. }
  130.  
  131. template<int type> ID_STATIC_TEMPLATE ID_INLINE void idCmdSystem::ArgCompletion_Decl( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  132.     cmdSystem->ArgCompletion_DeclName( args, callback, type );
  133. }
  134.  
  135. ID_INLINE void idCmdSystem::ArgCompletion_FileName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  136.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "/", true, "", NULL );
  137. }
  138.  
  139. // RAVEN BEGIN
  140. // mekberg: added
  141. ID_INLINE void idCmdSystem::ArgCompletion_GuiName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  142.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "guis/", false, ".gui", NULL );
  143. }
  144. // RAVEN END
  145.  
  146. ID_INLINE void idCmdSystem::ArgCompletion_MapName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  147.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "maps/", true, ".map", NULL );
  148. }
  149.  
  150. ID_INLINE void idCmdSystem::ArgCompletion_ModelName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  151.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "models/", false, ".lwo", ".ase", ".md5mesh", ".ma", NULL );
  152. }
  153.  
  154. ID_INLINE void idCmdSystem::ArgCompletion_SoundName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  155.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "sound/", false, ".wav", ".ogg", NULL );
  156. }
  157.  
  158. ID_INLINE void idCmdSystem::ArgCompletion_ImageName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  159.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "/", false, ".tga", ".dds", ".jpg", ".pcx", NULL );
  160. }
  161.  
  162. ID_INLINE void idCmdSystem::ArgCompletion_VideoName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  163.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "video/", false, ".roq", NULL );
  164. }
  165.  
  166. //RAVEN BEGIN
  167. //nrausch: standalone video support
  168. ID_INLINE void idCmdSystem::ArgCompletion_StandaloneVideoName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  169.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "video/", false, ".wmv", NULL );
  170. }
  171. //RAVEN END
  172.  
  173. ID_INLINE void idCmdSystem::ArgCompletion_ConfigName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  174.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "/", true, ".cfg", NULL );
  175. }
  176.  
  177. ID_INLINE void idCmdSystem::ArgCompletion_SaveGame( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  178.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "SaveGames/", true, ".save", NULL );
  179. }
  180.  
  181. ID_INLINE void idCmdSystem::ArgCompletion_DemoName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
  182.     cmdSystem->ArgCompletion_FolderExtension( args, callback, "demos/", true, ".demo", NULL );
  183. }
  184.  
  185. #endif /* !__CMDSYSTEM_H__ */
  186.