changed copyright years in source files
[fegdk.git] / core / code / system / f_console.h
bloba061ea86c05c8c0a0b42d4ffde3974a38a10ce0f
1 /*
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
19 Alexey Yakovenko
20 waker@users.sourceforge.net
23 #ifndef __F_CONSOLE_H
24 #define __F_CONSOLE_H
26 #include "f_string.h"
27 #include "f_math.h"
28 #include "f_helpers.h"
29 #include "f_baseobject.h"
30 //#include "f_fontft.h"
32 namespace fe
35 class console;
36 /**
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);
42 int Cmd_Argc (void);
43 const char *Cmd_Argv(int arg);
44 void Con_Printf (const char *fmt, ...);
46 template <int num, int strsize> class fixedStrDeque
48 public:
49 char pool[num][strsize];
50 int cnt;
51 int start;
53 fixedStrDeque (void)
55 cnt = 0;
56 start = 0;
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);
64 return;
66 if (cnt == num)
68 strcpy (pool[start], str);
69 start++;
70 if (start >= num)
71 start -= num;
73 else
75 strcpy (pool[start+cnt], str);
76 cnt++;
80 const char *get (int idx)
82 idx += start;
83 while (idx >= cnt)
84 idx -= cnt;
85 return pool[idx];
89 enum
91 MAX_FIELD_SIZE = 256
94 struct field_t
96 char buffer[MAX_FIELD_SIZE];
97 int cursor;
98 int matchCount;
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
112 protected:
114 enum {
115 MAX_CMD_HISTORY = 100,
116 MAX_MESSAGE_HISTORY = 100,
117 MAX_MESSAGE_LEN = 100,
118 MAX_ALIASES = 100,
119 MAX_ALIAS_LEN = 100,
120 MAX_COMMANDS = 1000,
121 MAX_ALIAS_NAME = 32
124 fixedStrDeque<MAX_CMD_HISTORY, MAX_MESSAGE_LEN> mCmdHistory;
125 fixedStrDeque<MAX_MESSAGE_HISTORY, MAX_MESSAGE_LEN> mMessageHistory;
127 int mCursor;
128 int mCurrentCmd;
130 struct command_t
132 const char *name;
133 void (*exec)(void);
134 command_t *hashNext;
137 struct alias_t
139 char left[MAX_ALIAS_NAME];
140 char right[MAX_ALIAS_LEN];
143 enum
145 CMD_HASH_SIZE = 256
147 command_t mCommands[MAX_COMMANDS];
148 int mNumCommands;
149 command_t* mCommandHash[CMD_HASH_SIZE];
151 alias_t mAliases[MAX_ALIASES];
152 int mNumAliases;
154 bool mVisible;
156 field_t mInput;
157 // char mInput[MAX_MESSAGE_LEN];
158 // int mInputCursor;
160 float mToggleTime;
162 ~console (void);
164 int maxNumLines (void) const;
166 command_t* commandFind (const char *name);
168 public:
170 console (const char *logFName = NULL);
172 void render (void);
173 void show (bool);
174 void toggle (void);
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