From 6c20f77330468a954ca2abcd396ab4135ea176fd Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 24 May 2008 10:15:06 +0000 Subject: (svn r13228) -Codechange: split console.h. --- src/console.cpp | 3 +- src/console.h | 161 ----------------------------------------- src/console_cmds.cpp | 2 +- src/console_func.h | 31 ++++++++ src/console_gui.h | 13 ++++ src/console_internal.h | 138 +++++++++++++++++++++++++++++++++++ src/console_type.h | 14 ++++ src/debug.cpp | 2 +- src/main_gui.cpp | 2 +- src/network/network.cpp | 2 +- src/network/network_client.cpp | 2 +- src/network/network_server.cpp | 2 +- src/openttd.cpp | 2 +- src/settings.cpp | 2 +- src/texteff.cpp | 2 +- src/tgp.cpp | 1 - src/toolbar_gui.cpp | 2 +- src/video/dedicated_v.cpp | 2 +- src/window.cpp | 3 +- 19 files changed, 211 insertions(+), 175 deletions(-) delete mode 100644 src/console.h create mode 100644 src/console_func.h create mode 100644 src/console_gui.h create mode 100644 src/console_internal.h create mode 100644 src/console_type.h (limited to 'src') diff --git a/src/console.cpp b/src/console.cpp index b93100825..2aeed9cc3 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -7,10 +7,11 @@ #include "gui.h" #include "textbuf_gui.h" #include "window_gui.h" +#include "console_gui.h" #include "variables.h" #include #include -#include "console.h" +#include "console_internal.h" #include "network/network.h" #include "network/network_data.h" #include "network/network_server.h" diff --git a/src/console.h b/src/console.h deleted file mode 100644 index 4c57ad532..000000000 --- a/src/console.h +++ /dev/null @@ -1,161 +0,0 @@ -/* $Id$ */ - -/** @file console.h In-game console. */ - -#ifndef CONSOLE_H -#define CONSOLE_H - -#include "window_type.h" - -/* maximum length of a typed in command */ -#define ICON_CMDLN_SIZE 255 -/* maximum length of a totally expanded command */ -#define ICON_MAX_STREAMSIZE 1024 - -enum IConsoleVarTypes { - ICONSOLE_VAR_BOOLEAN, - ICONSOLE_VAR_BYTE, - ICONSOLE_VAR_UINT16, - ICONSOLE_VAR_UINT32, - ICONSOLE_VAR_INT16, - ICONSOLE_VAR_INT32, - ICONSOLE_VAR_STRING -}; - -enum IConsoleModes { - ICONSOLE_FULL, - ICONSOLE_OPENED, - ICONSOLE_CLOSED -}; - -enum IConsoleHookTypes { - ICONSOLE_HOOK_ACCESS, - ICONSOLE_HOOK_PRE_ACTION, - ICONSOLE_HOOK_POST_ACTION -}; - -/** --Hooks-- - * Hooks are certain triggers get get accessed/executed on either - * access, before execution/change or after execution/change. This allows - * for general flow of permissions or special action needed in some cases - */ -typedef bool IConsoleHook(); -struct IConsoleHooks{ - IConsoleHook *access; ///< trigger when accessing the variable/command - IConsoleHook *pre; ///< trigger before the variable/command is changed/executed - IConsoleHook *post; ///< trigger after the variable/command is changed/executed -}; - -/** --Commands-- - * Commands are commands, or functions. They get executed once and any - * effect they produce are carried out. The arguments to the commands - * are given to them, each input word seperated by a double-quote (") is an argument - * If you want to handle multiple words as one, enclose them in double-quotes - * eg. 'say "hello sexy boy"' - */ -typedef bool (IConsoleCmdProc)(byte argc, char *argv[]); - -struct IConsoleCmd { - char *name; ///< name of command - IConsoleCmd *next; ///< next command in list - - IConsoleCmdProc *proc; ///< process executed when command is typed - IConsoleHooks hook; ///< any special trigger action that needs executing -}; - -/** --Variables-- - * Variables are pointers to real ingame variables which allow for - * changing while ingame. After changing they keep their new value - * and can be used for debugging, gameplay, etc. It accepts: - * - no arguments; just print out current value - * - '= ' to assign a new value to the variable - * - '++' to increase value by one - * - '--' to decrease value by one - */ -struct IConsoleVar { - char *name; ///< name of the variable - IConsoleVar *next; ///< next variable in list - - void *addr; ///< the address where the variable is pointing at - uint32 size; ///< size of the variable, used for strings - char *help; ///< the optional help string shown when requesting information - IConsoleVarTypes type; ///< type of variable (for correct assignment/output) - IConsoleCmdProc *proc; ///< some variables need really special handling, use a callback function for that - IConsoleHooks hook; ///< any special trigger action that needs executing -}; - -/** --Aliases-- - * Aliases are like shortcuts for complex functions, variable assignments, - * etc. You can use a simple alias to rename a longer command (eg 'lv' for - * 'list_vars' for example), or concatenate more commands into one - * (eg. 'ng' for 'load %A; unpause; debug_level 5'). Aliases can parse the arguments - * given to them in the command line. - * - "%A - %Z" substitute arguments 1 t/m 26 - * - "%+" lists all parameters keeping them seperated - * - "%!" also lists all parameters but presenting them to the aliased command as one argument - * - ";" allows for combining commands (see example 'ng') - */ -struct IConsoleAlias { - char *name; ///< name of the alias - IConsoleAlias *next; ///< next alias in list - - char *cmdline; ///< command(s) that is/are being aliased -}; - -/* console parser */ -extern IConsoleCmd *_iconsole_cmds; ///< list of registred commands -extern IConsoleVar *_iconsole_vars; ///< list of registred vars -extern IConsoleAlias *_iconsole_aliases; ///< list of registred aliases - -/* console colors/modes */ -extern byte _icolour_def; -extern byte _icolour_err; -extern byte _icolour_warn; -extern byte _icolour_dbg; -extern byte _icolour_cmd; -extern IConsoleModes _iconsole_mode; - -/* console functions */ -void IConsoleInit(); -void IConsoleFree(); -void IConsoleClearBuffer(); -void IConsoleResize(Window *w); -void IConsoleSwitch(); -void IConsoleClose(); -void IConsoleOpen(); - -/* console output */ -void IConsolePrint(uint16 color_code, const char *string); -void CDECL IConsolePrintF(uint16 color_code, const char *s, ...); -void IConsoleDebug(const char *dbg, const char *string); -void IConsoleWarning(const char *string); -void IConsoleError(const char *string); - -/* Commands */ -void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc); -void IConsoleAliasRegister(const char *name, const char *cmd); -IConsoleCmd *IConsoleCmdGet(const char *name); -IConsoleAlias *IConsoleAliasGet(const char *name); - -/* Variables */ -void IConsoleVarRegister(const char *name, void *addr, IConsoleVarTypes type, const char *help); -void IConsoleVarStringRegister(const char *name, void *addr, uint32 size, const char *help); -IConsoleVar* IConsoleVarGet(const char *name); -void IConsoleVarPrintGetValue(const IConsoleVar *var); -void IConsoleVarPrintSetValue(const IConsoleVar *var); - -/* Parser */ -void IConsoleCmdExec(const char *cmdstr); -void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[]); - -/* console std lib (register ingame commands/aliases/variables) */ -void IConsoleStdLibRegister(); - -/* Hooking code */ -void IConsoleCmdHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc); -void IConsoleVarHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc); -void IConsoleVarProcAdd(const char *name, IConsoleCmdProc *proc); - -/* Supporting functions */ -bool GetArgumentInteger(uint32 *value, const char *arg); -#endif /* CONSOLE_H */ diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 49e003427..2312b7370 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -4,7 +4,7 @@ #include "stdafx.h" #include "openttd.h" -#include "console.h" +#include "console_internal.h" #include "debug.h" #include "engine_func.h" #include "landscape.h" diff --git a/src/console_func.h b/src/console_func.h new file mode 100644 index 000000000..4ec762bdf --- /dev/null +++ b/src/console_func.h @@ -0,0 +1,31 @@ +/* $Id$ */ + +/** @file console_func.h Console functions used outside of the console code. */ + +#ifndef CONSOLE_FUNC_H +#define CONSOLE_FUNC_H + +#include "console_type.h" + +/* console colors/modes */ +extern byte _icolour_def; +extern byte _icolour_err; +extern byte _icolour_warn; +extern byte _icolour_dbg; +extern byte _icolour_cmd; +extern IConsoleModes _iconsole_mode; + +/* console functions */ +void IConsoleInit(); +void IConsoleFree(); +void IConsoleClose(); + +/* console output */ +void IConsolePrint(uint16 color_code, const char *string); +void CDECL IConsolePrintF(uint16 color_code, const char *s, ...); +void IConsoleDebug(const char *dbg, const char *string); + +/* Parser */ +void IConsoleCmdExec(const char *cmdstr); + +#endif /* CONSOLE_FUNC_H */ diff --git a/src/console_gui.h b/src/console_gui.h new file mode 100644 index 000000000..7d7619fda --- /dev/null +++ b/src/console_gui.h @@ -0,0 +1,13 @@ +/* $Id$ */ + +/** @file console_gui.h GUI related functions in the console. */ + +#ifndef CONSOLE_GUI_H +#define CONSOLE_GUI_H + +#include "window_type.h" + +void IConsoleResize(Window *w); +void IConsoleSwitch(); + +#endif /* CONSOLE_GUI_H */ diff --git a/src/console_internal.h b/src/console_internal.h new file mode 100644 index 000000000..f4884e3da --- /dev/null +++ b/src/console_internal.h @@ -0,0 +1,138 @@ +/* $Id$ */ + +/** @file console_internal.h Internally used functions for the console. */ + +#ifndef CONSOLE_INTERNAL_H +#define CONSOLE_INTERNAL_H + +#include "console_func.h" + +/* maximum length of a typed in command */ +#define ICON_CMDLN_SIZE 255 +/* maximum length of a totally expanded command */ +#define ICON_MAX_STREAMSIZE 1024 + +enum IConsoleVarTypes { + ICONSOLE_VAR_BOOLEAN, + ICONSOLE_VAR_BYTE, + ICONSOLE_VAR_UINT16, + ICONSOLE_VAR_UINT32, + ICONSOLE_VAR_INT16, + ICONSOLE_VAR_INT32, + ICONSOLE_VAR_STRING +}; + +enum IConsoleHookTypes { + ICONSOLE_HOOK_ACCESS, + ICONSOLE_HOOK_PRE_ACTION, + ICONSOLE_HOOK_POST_ACTION +}; + +/** --Hooks-- + * Hooks are certain triggers get get accessed/executed on either + * access, before execution/change or after execution/change. This allows + * for general flow of permissions or special action needed in some cases + */ +typedef bool IConsoleHook(); +struct IConsoleHooks{ + IConsoleHook *access; ///< trigger when accessing the variable/command + IConsoleHook *pre; ///< trigger before the variable/command is changed/executed + IConsoleHook *post; ///< trigger after the variable/command is changed/executed +}; + +/** --Commands-- + * Commands are commands, or functions. They get executed once and any + * effect they produce are carried out. The arguments to the commands + * are given to them, each input word seperated by a double-quote (") is an argument + * If you want to handle multiple words as one, enclose them in double-quotes + * eg. 'say "hello sexy boy"' + */ +typedef bool (IConsoleCmdProc)(byte argc, char *argv[]); + +struct IConsoleCmd { + char *name; ///< name of command + IConsoleCmd *next; ///< next command in list + + IConsoleCmdProc *proc; ///< process executed when command is typed + IConsoleHooks hook; ///< any special trigger action that needs executing +}; + +/** --Variables-- + * Variables are pointers to real ingame variables which allow for + * changing while ingame. After changing they keep their new value + * and can be used for debugging, gameplay, etc. It accepts: + * - no arguments; just print out current value + * - '= ' to assign a new value to the variable + * - '++' to increase value by one + * - '--' to decrease value by one + */ +struct IConsoleVar { + char *name; ///< name of the variable + IConsoleVar *next; ///< next variable in list + + void *addr; ///< the address where the variable is pointing at + uint32 size; ///< size of the variable, used for strings + char *help; ///< the optional help string shown when requesting information + IConsoleVarTypes type; ///< type of variable (for correct assignment/output) + IConsoleCmdProc *proc; ///< some variables need really special handling, use a callback function for that + IConsoleHooks hook; ///< any special trigger action that needs executing +}; + +/** --Aliases-- + * Aliases are like shortcuts for complex functions, variable assignments, + * etc. You can use a simple alias to rename a longer command (eg 'lv' for + * 'list_vars' for example), or concatenate more commands into one + * (eg. 'ng' for 'load %A; unpause; debug_level 5'). Aliases can parse the arguments + * given to them in the command line. + * - "%A - %Z" substitute arguments 1 t/m 26 + * - "%+" lists all parameters keeping them seperated + * - "%!" also lists all parameters but presenting them to the aliased command as one argument + * - ";" allows for combining commands (see example 'ng') + */ +struct IConsoleAlias { + char *name; ///< name of the alias + IConsoleAlias *next; ///< next alias in list + + char *cmdline; ///< command(s) that is/are being aliased +}; + +/* console parser */ +extern IConsoleCmd *_iconsole_cmds; ///< list of registred commands +extern IConsoleVar *_iconsole_vars; ///< list of registred vars +extern IConsoleAlias *_iconsole_aliases; ///< list of registred aliases + +/* console functions */ +void IConsoleClearBuffer(); +void IConsoleOpen(); + +/* console output */ +void IConsoleWarning(const char *string); +void IConsoleError(const char *string); + +/* Commands */ +void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc); +void IConsoleAliasRegister(const char *name, const char *cmd); +IConsoleCmd *IConsoleCmdGet(const char *name); +IConsoleAlias *IConsoleAliasGet(const char *name); + +/* Variables */ +void IConsoleVarRegister(const char *name, void *addr, IConsoleVarTypes type, const char *help); +void IConsoleVarStringRegister(const char *name, void *addr, uint32 size, const char *help); +IConsoleVar* IConsoleVarGet(const char *name); +void IConsoleVarPrintGetValue(const IConsoleVar *var); +void IConsoleVarPrintSetValue(const IConsoleVar *var); + +/* Parser */ +void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[]); + +/* console std lib (register ingame commands/aliases/variables) */ +void IConsoleStdLibRegister(); + +/* Hooking code */ +void IConsoleCmdHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc); +void IConsoleVarHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc); +void IConsoleVarProcAdd(const char *name, IConsoleCmdProc *proc); + +/* Supporting functions */ +bool GetArgumentInteger(uint32 *value, const char *arg); +#endif /* CONSOLE_H */ diff --git a/src/console_type.h b/src/console_type.h new file mode 100644 index 000000000..58b26b49b --- /dev/null +++ b/src/console_type.h @@ -0,0 +1,14 @@ +/* $Id$ */ + +/** @file console_type.h Globally used console related types. */ + +#ifndef CONSOLE_TYPE_H +#define CONSOLE_TYPE_H + +enum IConsoleModes { + ICONSOLE_FULL, + ICONSOLE_OPENED, + ICONSOLE_CLOSED +}; + +#endif /* CONSOLE_TYPE_H */ diff --git a/src/debug.cpp b/src/debug.cpp index 9dbf2642c..eb829efed 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -6,7 +6,7 @@ #include #include #include "openttd.h" -#include "console.h" +#include "console_func.h" #include "debug.h" #include "string_func.h" #include "network/core/core.h" diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 6eaab74e6..23f5169d9 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -13,7 +13,7 @@ #include "viewport_func.h" #include "command_func.h" #include "news_gui.h" -#include "console.h" +#include "console_gui.h" #include "waypoint.h" #include "genworld.h" #include "transparency_gui.h" diff --git a/src/network/network.cpp b/src/network/network.cpp index 30a0cc957..dfb086da0 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -23,7 +23,7 @@ #include "core/tcp.h" #include "core/core.h" #include "network_gui.h" -#include "../console.h" /* IConsoleCmdExec */ +#include "../console_func.h" #include /* va_list */ #include "../md5.h" #include "../fileio.h" diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 02608bc38..35b60029c 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -14,7 +14,7 @@ #include "network_gui.h" #include "../saveload.h" #include "../command_func.h" -#include "../console.h" +#include "../console_func.h" #include "../variables.h" #include "../ai/ai.h" #include "../core/alloc_func.hpp" diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index e75b2b001..ec3010840 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -15,7 +15,7 @@ #include "../date_func.h" #include "network_server.h" #include "network_udp.h" -#include "../console.h" +#include "../console_func.h" #include "../command_func.h" #include "../saveload.h" #include "../station_base.h" diff --git a/src/openttd.cpp b/src/openttd.cpp index b8ca7f312..0466f0716 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -41,7 +41,7 @@ #include "fios.h" #include "airport.h" #include "aircraft.h" -#include "console.h" +#include "console_func.h" #include "screenshot.h" #include "network/network.h" #include "signs_base.h" diff --git a/src/settings.cpp b/src/settings.cpp index da5190314..c49fdfc0f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -28,7 +28,7 @@ #include "network/network_internal.h" #include "settings_internal.h" #include "command_func.h" -#include "console.h" +#include "console_func.h" #include "saveload.h" #include "npf.h" #include "yapf/yapf.h" diff --git a/src/texteff.cpp b/src/texteff.cpp index 61eabd4a1..7cadbc347 100644 --- a/src/texteff.cpp +++ b/src/texteff.cpp @@ -6,7 +6,7 @@ #include "openttd.h" #include "landscape.h" #include "gfx_func.h" -#include "console.h" +#include "console_func.h" #include "variables.h" #include "blitter/factory.hpp" #include "texteff.hpp" diff --git a/src/tgp.cpp b/src/tgp.cpp index 28169b455..2dced280b 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -10,7 +10,6 @@ #include "variables.h" #include "void_map.h" #include "tgp.h" -#include "console.h" #include "genworld.h" #include "core/alloc_func.hpp" #include "core/random_func.hpp" diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 7cc462cbd..6377d4909 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -35,7 +35,7 @@ #include "signs_func.h" #include "fios.h" #include "functions.h" -#include "console.h" +#include "console_gui.h" #include "news_gui.h" #include "tilehighlight_func.h" diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index 523bb403d..8af223e8e 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -11,7 +11,7 @@ #include "../gfx_func.h" #include "../network/network.h" #include "../network/network_internal.h" -#include "../console.h" +#include "../console_func.h" #include "../variables.h" #include "../genworld.h" #include "../fileio.h" diff --git a/src/window.cpp b/src/window.cpp index 0416d6a22..c5d127538 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -8,7 +8,8 @@ #include "debug.h" #include "player_func.h" #include "gfx_func.h" -#include "console.h" +#include "console_func.h" +#include "console_gui.h" #include "viewport_func.h" #include "variables.h" #include "genworld.h" -- cgit v1.2.3-70-g09d2