📄 console.h
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
#ifndef _PLATFORM_H_
#include "platform/platform.h"
#endif
#ifndef _BITSET_H_
#include "core/bitSet.h"
#endif
#include <stdarg.h>
class SimObject;
struct EnumTable;
class Namespace;
/// Indicates that warnings about undefined script variables should be displayed.
///
/// @note This is set and controlled by script.
extern bool gWarnUndefinedScriptVariables;
enum StringTableConstants
{
StringTagPrefixByte = 0x01 ///< Magic value prefixed to tagged strings.
};
/// Represents an entry in the log.
struct ConsoleLogEntry
{
/// This field indicates the severity of the log entry.
///
/// Log entries are filtered and displayed differently based on
/// their severity. Errors are highlighted red, while normal entries
/// are displayed as normal text. Often times, the engine will be
/// configured to hide all log entries except warnings or errors,
/// or to perform a special notification when it encounters an error.
enum Level
{
Normal = 0,
Warning,
Error,
NUM_CLASS
} mLevel;
/// Used to associate a log entry with a module.
///
/// Log entries can come from different sources; for instance,
/// the scripting engine, or the network code. This allows the
/// logging system to be aware of where different log entries
/// originated from.
enum Type
{
General = 0,
Assert,
Script,
GUI,
Network,
NUM_TYPE
} mType;
/// Indicates the actual log entry.
///
/// This contains a description of the event being logged.
/// For instance, "unable to access file", or "player connected
/// successfully", or nearly anything else you might imagine.
///
/// Typically, the description should contain a concise, descriptive
/// string describing whatever is being logged. Whenever possible,
/// include useful details like the name of the file being accessed,
/// or the id of the player or GuiControl, so that if a log needs
/// to be used to locate a bug, it can be done as painlessly as
/// possible.
const char *mString;
};
/// Scripting engine representation of an enum.
///
/// This data structure is used by the scripting engine
/// to expose enumerations to the scripting language. It
/// acts to relate named constants to integer values, just
/// like an enum in C++.
struct EnumTable
{
/// Number of enumerated items in the table.
S32 size;
/// This represents a specific item in the enumeration.
struct Enums
{
S32 index; ///< Index label maps to.
const char *label;///< Label for this index.
};
Enums *table;
/// Constructor.
///
/// This sets up the EnumTable with predefined data.
///
/// @param sSize Size of the table.
/// @param sTable Pointer to table of Enums.
///
/// @see gLiquidTypeTable
/// @see gAlignTable
EnumTable(S32 sSize, Enums *sTable)
{ size = sSize; table = sTable; }
};
typedef const char *StringTableEntry;
/// @defgroup console_callbacks Scripting Engine Callbacks
///
/// The scripting engine makes heavy use of callbacks to represent
/// function exposed to the scripting language. StringCallback,
/// IntCallback, FloatCallback, VoidCallback, and BoolCallback all
/// represent exposed script functions returning different types.
///
/// ConsumerCallback is used with the function Con::addConsumer; functions
/// registered with Con::addConsumer are called whenever something is outputted
/// to the console. For instance, the TelnetConsole registers itself with the
/// console so it can echo the console over the network.
///
/// @note Callbacks to the scripting language - for instance, onExit(), which is
/// a script function called when the engine is shutting down - are handled
/// using Con::executef() and kin.
/// @{
///
typedef const char * (*StringCallback)(SimObject *obj, S32 argc, const char *argv[]);
typedef S32 (*IntCallback)(SimObject *obj, S32 argc, const char *argv[]);
typedef F32 (*FloatCallback)(SimObject *obj, S32 argc, const char *argv[]);
typedef void (*VoidCallback)(SimObject *obj, S32 argc, const char *argv[]); // We have it return a value so things don't break..
typedef bool (*BoolCallback)(SimObject *obj, S32 argc, const char *argv[]);
typedef void (*ConsumerCallback)(ConsoleLogEntry::Level level, const char *consoleLine);
/// @}
/// @defgroup console_types Scripting Engine Type Functions
///
/// @see Con::registerType
/// @{
typedef const char* (*GetDataFunction)(void *dptr, EnumTable *tbl, BitSet32 flag);
typedef void (*SetDataFunction)(void *dptr, S32 argc, const char **argv, EnumTable *tbl, BitSet32 flag);
/// @}
/// This namespace contains the core of the console functionality.
///
/// @section con_intro Introduction
///
/// The console is a key part of Torque's architecture. It allows direct run-time control
/// of many aspects of the engine.
///
/// @nosubgrouping
namespace Con
{
/// Various configuration constants.
enum Constants
{
/// This is the version number associated with DSO files.
///
/// If you make any changes to the way the scripting language works
/// (such as DSO format changes, adding/removing op-codes) that would
/// break compatibility, then you should increment this.
///
/// If you make a really major change, increment it to the next multiple
/// of ten.
///
/// 12/29/04 - BJG - 33->34 Removed some opcodes, part of namespace upgrade.
/// 12/30/04 - BJG - 34->35 Reordered some things, further general shuffling.
/// 11/03/05 - BJG - 35->36 Integrated new debugger code.
DSOVersion = 36,
MaxLineLength = 512, ///< Maximum length of a line of console input.
MaxDataTypes = 256 ///< Maximum number of registered data types.
};
/// @name Control Functions
///
/// The console must be initialized and shutdown appropriately during the
/// lifetime of the app. These functions are used to manage this behavior.
///
/// @note Torque deals with this aspect of console management, so you don't need
/// to call these functions in normal usage of the engine.
/// @{
/// Initializes the console.
///
/// This performs the following steps:
/// - Calls Namespace::init() to initialize the scripting namespace hierarchy.
/// - Calls ConsoleConstructor::setup() to initialize globally defined console
/// methods and functions.
/// - Registers some basic global script variables.
/// - Calls AbstractClassRep::init() to initialize Torque's class database.
/// - Registers some basic global script functions that couldn't usefully
/// be defined anywhere else.
void init();
/// Shuts down the console.
///
/// This performs the following steps:
/// - Closes the console log file.
/// - Calls Namespace::shutdown() to shut down the scripting namespace hierarchy.
void shutdown();
/// Is the console active at this time?
bool isActive();
/// @}
/// @name Console Consumers
///
/// The console distributes its output through Torque by using
/// consumers. Every time a new line is printed to the console,
/// all the ConsumerCallbacks registered using addConsumer are
/// called, in order.
///
/// @note The GuiConsole control, which provides the on-screen
/// in-game console, uses a different technique to render
/// the console. It calls getLockLog() to lock the Vector
/// of on-screen console entries, then it renders them as
/// needed. While the Vector is locked, the console will
/// not change the Vector. When the GuiConsole control is
/// done with the console entries, it calls unlockLog()
/// to tell the console that it is again safe to modify
/// the Vector.
///
/// @see TelnetConsole
/// @see TelnetDebugger
/// @see WinConsole
/// @see MacCarbConsole
/// @see StdConsole
/// @see ConsoleLogger
///
/// @{
void addConsumer(ConsumerCallback cb);
void removeConsumer(ConsumerCallback cb);
/// @}
/// @name Miscellaneous
/// @{
/// Remove color marking information from a string.
///
/// @note It does this in-place, so be careful! It may
/// potentially blast data if you're not careful.
/// When in doubt, make a copy of the string first.
void stripColorChars(char* line);
/// Convert from a relative script path to an absolute script path.
///
/// This is used in (among other places) the exec() script function, which
/// takes a parameter indicating a script file and executes it. Script paths
/// can be one of:
/// - <b>Absolute:</b> <i>fps/foo/bar.cs</i> Paths of this sort are passed
/// through.
/// - <b>Mod-relative:</b> <i>~/foo/bar.cs</i> Paths of this sort have their
/// replaced with the name of the current mod.
/// - <b>File-relative:</b> <i>./baz/blip.cs</i> Paths of this sort are
/// calculated relative to the path of the current scripting file.
///
/// @note This function determines paths relative to the currently executing
/// CodeBlock. Calling it outside of script execution will result in
/// it directly copying src to filename, since it won't know to what the
/// path is relative!
///
/// @param filename Pointer to string buffer to fill with absolute path.
/// @param size Size of buffer pointed to by filename.
/// @param src Original, possibly relative script path.
bool expandScriptFilename(char *filename, U32 size, const char *src);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -