1 /* 2 ** c_dispatch.h 3 ** 4 **--------------------------------------------------------------------------- 5 ** Copyright 1998-2006 Randy Heit 6 ** All rights reserved. 7 ** 8 ** Redistribution and use in source and binary forms, with or without 9 ** modification, are permitted provided that the following conditions 10 ** are met: 11 ** 12 ** 1. Redistributions of source code must retain the above copyright 13 ** notice, this list of conditions and the following disclaimer. 14 ** 2. Redistributions in binary form must reproduce the above copyright 15 ** notice, this list of conditions and the following disclaimer in the 16 ** documentation and/or other materials provided with the distribution. 17 ** 3. The name of the author may not be used to endorse or promote products 18 ** derived from this software without specific prior written permission. 19 ** 20 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 **--------------------------------------------------------------------------- 31 ** 32 */ 33 34 #ifndef __C_DISPATCH_H__ 35 #define __C_DISPATCH_H__ 36 37 #include "doomtype.h" 38 39 class FConfigFile; 40 class APlayerPawn; 41 42 // Class that can parse command lines 43 class FCommandLine 44 { 45 public: 46 FCommandLine (const char *commandline, bool no_escapes = false); 47 ~FCommandLine (); 48 int argc (); 49 char *operator[] (int i); args()50 const char *args () { return cmd; } 51 void Shift(); 52 53 private: 54 const char *cmd; 55 int _argc; 56 char **_argv; 57 long argsize; 58 bool noescapes; 59 }; 60 61 // Contains the contents of an exec'ed file 62 struct FExecList 63 { 64 TArray<FString> Commands; 65 TArray<FString> Pullins; 66 67 void AddCommand(const char *cmd, const char *file = NULL); 68 void ExecCommands() const; 69 void AddPullins(TArray<FString> &wads) const; 70 }; 71 72 73 extern bool CheckCheatmode (bool printmsg = true); 74 75 FExecList *C_ParseCmdLineParams(FExecList *exec); 76 77 // Add commands to the console as if they were typed in. Can handle wait 78 // and semicolon-separated commands. This function may modify the source 79 // string, but the string will be restored to its original state before 80 // returning. Therefore, commands passed must not be in read-only memory. 81 void AddCommandString (char *text, int keynum=0); 82 83 // Process a single console command. Does not handle wait. 84 void C_DoCommand (const char *cmd, int keynum=0); 85 86 FExecList *C_ParseExecFile(const char *file, FExecList *source); 87 void C_SearchForPullins(FExecList *exec, const char *file, class FCommandLine &args); 88 bool C_ExecFile(const char *file); 89 90 // Write out alias commands to a file for all current aliases. 91 void C_ArchiveAliases (FConfigFile *f); 92 93 void C_SetAlias (const char *name, const char *cmd); 94 void C_ClearAliases (); 95 96 // build a single string out of multiple strings 97 FString BuildString (int argc, FString *argv); 98 99 typedef void (*CCmdRun) (FCommandLine &argv, APlayerPawn *instigator, int key); 100 101 class FConsoleCommand 102 { 103 public: 104 FConsoleCommand (const char *name, CCmdRun RunFunc); 105 virtual ~FConsoleCommand (); 106 virtual bool IsAlias (); PrintCommand()107 void PrintCommand () { Printf ("%s\n", m_Name); } 108 109 virtual void Run (FCommandLine &args, APlayerPawn *instigator, int key); 110 static FConsoleCommand* FindByName (const char* name); 111 112 FConsoleCommand *m_Next, **m_Prev; 113 char *m_Name; 114 115 enum { HASH_SIZE = 251 }; // Is this prime? 116 117 protected: 118 FConsoleCommand (); 119 bool AddToHash (FConsoleCommand **table); 120 121 CCmdRun m_RunFunc; 122 123 }; 124 125 #define CCMD(n) \ 126 void Cmd_##n (FCommandLine &, APlayerPawn *, int key); \ 127 FConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \ 128 void Cmd_##n (FCommandLine &argv, APlayerPawn *who, int key) 129 130 const int KEY_DBLCLICKED = 0x8000; 131 132 class FConsoleAlias : public FConsoleCommand 133 { 134 public: 135 FConsoleAlias (const char *name, const char *command, bool noSave); 136 ~FConsoleAlias (); 137 void Run (FCommandLine &args, APlayerPawn *Instigator, int key); 138 bool IsAlias (); 139 void PrintAlias (); 140 void Archive (FConfigFile *f); 141 void Realias (const char *command, bool noSave); 142 void SafeDelete (); 143 protected: 144 FString m_Command[2]; // Slot 0 is saved to the ini, slot 1 is not. 145 bool bDoSubstitution; 146 bool bRunning; 147 bool bKill; 148 }; 149 150 // Actions 151 struct FButtonStatus 152 { 153 enum { MAX_KEYS = 6 }; // Maximum number of keys that can press this button 154 155 WORD Keys[MAX_KEYS]; 156 BYTE bDown; // Button is down right now 157 BYTE bWentDown; // Button went down this tic 158 BYTE bWentUp; // Button went up this tic 159 BYTE padTo16Bytes; 160 161 bool PressKey (int keynum); // Returns true if this key caused the button to be pressed. 162 bool ReleaseKey (int keynum); // Returns true if this key is no longer pressed. ResetTriggersFButtonStatus163 void ResetTriggers () { bWentDown = bWentUp = false; } ResetFButtonStatus164 void Reset () { bDown = bWentDown = bWentUp = false; } 165 }; 166 167 extern FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack, 168 Button_Attack, Button_Speed, Button_MoveRight, Button_MoveLeft, 169 Button_Strafe, Button_LookDown, Button_LookUp, Button_Back, 170 Button_Forward, Button_Right, Button_Left, Button_MoveDown, 171 Button_MoveUp, Button_Jump, Button_ShowScores, Button_Crouch, 172 Button_Zoom, Button_Reload, 173 Button_User1, Button_User2, Button_User3, Button_User4, 174 Button_AM_PanLeft, Button_AM_PanRight, Button_AM_PanDown, Button_AM_PanUp, 175 Button_AM_ZoomIn, Button_AM_ZoomOut; 176 extern bool ParsingKeyConf; 177 178 void ResetButtonTriggers (); // Call ResetTriggers for all buttons 179 void ResetButtonStates (); // Same as above, but also clear bDown 180 181 extern unsigned int MakeKey (const char *s); 182 extern unsigned int MakeKey (const char *s, size_t len); 183 extern unsigned int SuperFastHash (const char *data, size_t len); 184 185 void execLogfile(const char *fn); 186 187 #endif //__C_DISPATCH_H__ 188