Odamex
Setting the Standard in Multiplayer Doom
common/c_dispatch.h
Go to the documentation of this file.
00001 // Emacs style mode select   -*- C++ -*-
00002 //-----------------------------------------------------------------------------
00003 //
00004 // $Id: c_dispatch.h 1788 2010-08-24 04:42:57Z russellrice $
00005 //
00006 // Copyright (C) 1998-2006 by Randy Heit (ZDoom).
00007 // Copyright (C) 2006-2010 by The Odamex Team.
00008 //
00009 // This program is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // DESCRIPTION:
00020 //      Argument processing (?)
00021 //
00022 //-----------------------------------------------------------------------------
00023 
00024 
00025 #ifndef __C_DISPATCH_H__
00026 #define __C_DISPATCH_H__
00027 
00028 #include "dobject.h"
00029 
00030 #include <string>
00031 #include <vector>
00032 
00033 #define HASH_SIZE       251                             // I think this is prime
00034 
00035 void C_ExecCmdLineParams (bool onlyset, bool onlylogfile);
00036 
00037 // add commands to the console as if they were typed in
00038 // for map changing, etc
00039 void AddCommandString (std::string cmd, bool onlycvar = false);
00040 
00041 // parse a command string
00042 const char *ParseString (const char *data);
00043 
00044 // build a single string out of multiple strings
00045 std::string BuildString (size_t argc, const char **argv);
00046 std::string BuildString (size_t argc, std::vector<std::string> args);
00047 
00048 class DConsoleCommand : public DObject
00049 {
00050         DECLARE_CLASS (DConsoleCommand, DObject)
00051 public:
00052         DConsoleCommand (const char *name);
00053         virtual ~DConsoleCommand ();
00054         virtual void Run () = 0;
00055         virtual bool IsAlias () { return false; }
00056         void PrintCommand () { Printf (PRINT_HIGH, "%s\n", m_Name.c_str()); }
00057 
00058         std::string m_Name;
00059 
00060 protected:
00061         DConsoleCommand ();
00062 
00063         AActor *m_Instigator;
00064         size_t argc;
00065         char **argv;
00066         char *args;
00067 
00068         friend void C_DoCommand (const char *cmd);
00069 };
00070 
00071 #define BEGIN_COMMAND(n) \
00072         class Cmd_##n : public DConsoleCommand { \
00073                 public: \
00074                         Cmd_##n () : DConsoleCommand (#n) {} \
00075                         Cmd_##n (const char *name) : DConsoleCommand (name) {} \
00076                         void Run ()
00077 
00078 #define END_COMMAND(n)          }; \
00079         static Cmd_##n Cmd_instance##n;
00080 
00081 class DConsoleAlias : public DConsoleCommand
00082 {
00083         DECLARE_CLASS (DConsoleAlias, DConsoleCommand)
00084         bool state_lock;
00085 public:
00086         DConsoleAlias (const char *name, const char *command);
00087         virtual ~DConsoleAlias ();
00088         void Run ();
00089         bool IsAlias () { return true; }
00090         void PrintAlias () { Printf (PRINT_HIGH, "%s : %s\n", m_Name.c_str(), m_Command.c_str()); }
00091         void Archive (FILE *f);
00092 
00093         // Write out alias commands to a file for all current aliases.
00094         static void C_ArchiveAliases (FILE *f);
00095 protected:
00096         std::string m_Command;
00097         std::string m_CommandParam;
00098 };
00099 
00100 // Actions
00101 #define ACTION_MLOOK            0
00102 #define ACTION_KLOOK            1
00103 #define ACTION_USE                      2
00104 #define ACTION_ATTACK           3
00105 #define ACTION_SPEED            4
00106 #define ACTION_MOVERIGHT        5
00107 #define ACTION_MOVELEFT         6
00108 #define ACTION_STRAFE           7
00109 #define ACTION_LOOKDOWN         8
00110 #define ACTION_LOOKUP           9
00111 #define ACTION_BACK                     10
00112 #define ACTION_FORWARD          11
00113 #define ACTION_RIGHT            12
00114 #define ACTION_LEFT                     13
00115 #define ACTION_MOVEDOWN         14
00116 #define ACTION_MOVEUP           15
00117 #define ACTION_JUMP                     16
00118 #define ACTION_SHOWSCORES       17
00119 #define NUM_ACTIONS                     18
00120 
00121 extern byte Actions[NUM_ACTIONS];
00122 
00123 struct ActionBits
00124 {
00125         unsigned int    key;
00126         int                             index;
00127         char                    name[12];
00128 };
00129 
00130 extern unsigned int MakeKey (const char *s);
00131 
00132 #endif //__C_DISPATCH_H__
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends