2 fegdk: FE Game Development Kit
3 Copyright (C) 2001-2008 Alexey "waker" Yakovenko
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 waker@users.sourceforge.net
28 #include "f_helpers.h"
29 #include "f_baseobject.h"
30 //#include "f_fontft.h"
37 * Helper macros for quick console command creation
39 #define FE_REGISTER_CONSOLE_CMD(name) \
40 fe::g_engine->getConsole ()->addCommand (#name, Cmd_##name##_f);
43 const char *Cmd_Argv(int arg
);
44 void Con_Printf (const char *fmt
, ...);
46 template <int num
, int strsize
> class fixedStrDeque
49 char pool
[num
][strsize
];
59 void add (const char *str
)
61 if (strlen (str
) >= strsize
)
63 fprintf (stderr
, "ERROR: string is too long for fixedStrDeque<%d,%d>\n", num
, strsize
);
68 strcpy (pool
[start
], str
);
75 strcpy (pool
[start
+cnt
], str
);
80 const char *get (int idx
)
96 char buffer
[MAX_FIELD_SIZE
];
99 char shortestMatch
[MAX_FIELD_SIZE
];
101 void completeCommand (bool use_commands
, bool use_cvars
);
102 static void findMatches (const char *s
, field_t
*obj
);
103 static void printMatches (const char *s
, field_t
*obj
);
104 static void printCVarMatches (const char *s
, field_t
*obj
);
108 * Implementation of developer console, which can be used to create/run commands, query/set console variables, etc.
110 class FE_API console
: public baseObject
115 MAX_CMD_HISTORY
= 100,
116 MAX_MESSAGE_HISTORY
= 100,
117 MAX_MESSAGE_LEN
= 100,
124 fixedStrDeque
<MAX_CMD_HISTORY
, MAX_MESSAGE_LEN
> mCmdHistory
;
125 fixedStrDeque
<MAX_MESSAGE_HISTORY
, MAX_MESSAGE_LEN
> mMessageHistory
;
139 char left
[MAX_ALIAS_NAME
];
140 char right
[MAX_ALIAS_LEN
];
147 command_t mCommands
[MAX_COMMANDS
];
149 command_t
* mCommandHash
[CMD_HASH_SIZE
];
151 alias_t mAliases
[MAX_ALIASES
];
157 // char mInput[MAX_MESSAGE_LEN];
164 int maxNumLines (void) const;
166 command_t
* commandFind (const char *name
);
170 console (const char *logFName
= NULL
);
175 void msg (const char *message
);
176 void command (const char *cmd
);
177 bool keyDown (int); // returns true if accepted
178 bool isVisible (void) const { return mVisible
; }
179 void addCommand (const char *name
, void (*exec
)(void));
180 void setAlias (const char *name
, const char *value
);
181 void commandCompletion (void (*matchfunc
)(const char *cmd
, field_t
*data
), field_t
*data
);
187 #endif // __F_CONSOLE_H