openTRI 0.1
triConsole.h
1/*
2 * triConsole.h: Header for Ingame Console
3 * This file is part of the "tri Engine".
4 *
5 * Copyright (C) 2007 tri
6 * Copyright (C) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
7 *
8 * $Id: $
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#ifndef __TRICONSOLE_H__
26#define __TRICONSOLE_H__
27
28
29#include "triTypes.h"
30
31
32// A command function prototype
33// Arguments can be parsed through triCmdArgc() and triCmdArgv(n)/triCmdArgs()
34// Return must be 0 on success or a pointer to a string containing an error message
35// See cmd_* functions for examples
36typedef triChar* (*triCmdFunc)();
37
38#define TRI_INVALID_VAL (float)1e64
39
40#define TRI_CVAR_RDONLY 1
41#define TRI_CVAR_ALLOC 2
42#define TRI_CVAR_ARCHIVE 4
43
44// Macros for easy cvar declarations:
45// CVARF( cl_fpsmax, 60.0 );
46// CVARS( cl_playername, "Barney" );
47#define CVARS(x,s) triCVar x = { #x, s, TRI_INVALID_VAL, 0 };
48#define CVARF(x,f) triCVar x = { #x, #f, (triFloat)f, 0 };
49#define CVARS_RD(x,s) triCVar x = { #x, s, TRI_INVALID_VAL, TRI_CVAR_RDONLY };
50#define CVARF_RD(x,f) triCVar x = { #x, #f, (triFloat)f, TRI_CVAR_RDONLY };
51
52typedef struct triCVar {
53 triChar* name;
54 triChar* svalue;
55 triFloat fvalue;
56 triU32 flags;
57
58 struct triCVar* next;
59 } triCVar;
60
61
62//extern triCVar* triCVars;
63
64
65
66typedef struct triCmd {
67 triChar* name;
68 triCmdFunc func;
69
70 triS32 minargs; // minimum number of arguments needed for function
71 triChar* help; // argument list (optional arguments in [] brackets)
72 triChar* description; // short description of functionality
73 triChar* details; // detailed information on arguments
74
75 struct triCmd* next;
76 } triCmd;
77
78
79/*
80 * command aliases to allow a simple form of scripting as quake console does
81 * ie. alias "myscript" "echo 'this is text from a script!'; cl_fpsmax 30.0; echo 'Set FPS max to 30.';"
82 */
83typedef struct triCmdAlias {
84 triChar* name;
85 triChar* cmd;
86
87 struct triCmdAlias* next;
89
90
91/* keep private
92extern triCmdAlias* trialiases;
93
94extern triCmd* triCmds;
95*/
96
97
98
99#define CON_STDOUT 1 // Make console output to stdout
100
101
102#define MAXCONSOLECHARS 16*1024
103typedef struct triConsole {
104 triChar text[MAXCONSOLECHARS];
105 triS32 current; // offset to current line
106 triS32 x; // position in current line
107 triS32 display; // bottom line
108
109 triS32 numlines; // number of lines in console
110 triS32 maxlines; // maximal visible lines
111 triS32 visible;
112 } triConsole;
113
114
115extern triConsole tricon;
116
117
118/*
119 * triCVars - implementation following cvars from quake (tm)
120 */
121triFloat triatof( const triChar* str );
122
123void triCVarRegister( triCVar* var );
124void triCVarSet( const triChar* name, const triChar* value );
125void triCVarSetf( const triChar* name, const triFloat value );
126triChar* triCVarGet( const triChar* name );
127triFloat triCVarGetf( const triChar* name );
128
129triChar* triCVarComplete( const triChar* name );
130// Execute a cvar command (set value or return value)
131triS32 triCVarCmd();
132
133// Find a cvar matching the name
134triCVar* triCVarFind( const triChar* name );
135
136
137/*
138 * triAlias functionality
139 */
140
141// Register a new alias
142triChar* triAliasRegister( const triChar* name, const triChar* cmd );
143// Find an alias matching the name
144triCmdAlias* triAliasFind( const triChar* name );
145// Execute an alias command
146triS32 triAliasCmd();
147
148/*
149 * triCmd functionality
150 */
151
152// command argument parsing
153triS32 triCmdArgc();
154triChar* triCmdArgv( triS32 n );
155triChar* triCmdArgs();
156
157
158// Complete a command
159triChar* triCmdComplete( const triChar* name );
160// Register a new command
161triChar* triCmdRegister( const triChar* name, triCmdFunc func, const triS32 minargs, const triChar* help, const triChar* desc, const triChar* details );
162triCmd* triCmdFind( const triChar* name );
163// Execute a command
164triS32 triCmdCmd();
165
166// Execute the line containing cmds as if written to console
167void triCmdExecute( triChar* line );
168// Tokenize a line and make the tokens available through triCmdArgv(n). Return pointer to end of line
169triChar* triCmdTokenize( triChar* line );
170
171
172
173triChar* cmd_aliases();
174triChar* cmd_exit();
175triChar* cmd_cls();
176triChar* cmd_cmds();
177triChar* cmd_cvars();
178triChar* cmd_echo();
179triChar* cmd_wait();
180triChar* cmd_alias();
181triChar* cmd_exec();
182triChar* cmd_eval();
183
184
185/*
186 * triConsole functionality
187 */
188void triConsoleInit();
189void triConsoleClose();
190void triConsoleToggle();
191void triConsolePrint( const triChar* text );
192void triConsolePrintf( const triChar* fmt, ... );
193void triConsoleDraw();
194void triConsoleClear();
195void triConsoleResize( const triS32 lines );
196void triConsoleUpdate();
197triS32 triConsoleVisible();
198
199#endif // __TRICONSOLE_H__
Definition: triConsole.h:52
Definition: triConsole.h:83
Definition: triConsole.h:66
Definition: triConsole.h:103