Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Enumerations | Functions | Variables
console.cpp File Reference
#include "inexor/engine/console.hpp"
#include <boost/algorithm/clamp.hpp>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <memory>
#include <set>
#include <string>
#include "SDL_clipboard.h"
#include "SDL_keyboard.h"
#include "SDL_keycode.h"
#include "SDL_stdinc.h"
#include "inexor/engine/octaedit.hpp"
#include "inexor/engine/rendertext.hpp"
#include "inexor/fpsgame/client.hpp"
#include "inexor/fpsgame/fps.hpp"
#include "inexor/fpsgame/player.hpp"
#include "inexor/io/Logging.hpp"
#include "inexor/io/input/InputRouter.hpp"
#include "inexor/io/legacy/stream.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/network/legacy/cube_network.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_formatting.hpp"
#include "inexor/shared/cube_hash.hpp"
#include "inexor/shared/cube_loops.hpp"
#include "inexor/shared/cube_queue.hpp"
#include "inexor/shared/cube_tools.hpp"
#include "inexor/shared/cube_types.hpp"
#include "inexor/shared/cube_unicode.hpp"
#include "inexor/shared/cube_vector.hpp"
#include "inexor/shared/ents.hpp"
#include "inexor/shared/tools.hpp"
#include "inexor/ui/legacy/3dgui.hpp"
#include "inexor/ui/legacy/menus.hpp"
#include "inexor/util/legacy_time.hpp"

Classes

struct  cline
 
struct  keym
 
struct  hline
 
struct  releaseaction
 
struct  fileskey
 
struct  filesval
 

Macros

#define MAXCONLINES   1000
 
#define CONSTRLEN   512
 
#define MOD_KEYS   (KMOD_LCTRL|KMOD_RCTRL)
 

Enumerations

enum  { CF_COMPLETE = 1<<0, CF_EXECUTE = 1<<1 }
 
enum  { FILES_DIR = 0, FILES_LIST }
 

Functions

 VARFP (maxcon, 10, 200, MAXCONLINES,{while(conlines.length() > maxcon) delete[] conlines.pop().line;})
 
 VARP (confading, 0, 1, 1)
 
void conline (int type, const char *sf)
 Function which displayes console text ingame. (legacy UI) More...
 
 VAR (fullconsole, 0, 0, 1)
 
 ICOMMAND (toggleconsole,"",(),{fullconsole^=1;})
 
int rendercommand (int x, int y, int w)
 
 VARP (consize, 0, 5, 100)
 
 VARP (miniconsize, 0, 5, 100)
 
 VARP (miniconwidth, 0, 40, 100)
 
 VARP (confade, 0, 30, 60)
 
 VARP (miniconfade, 0, 30, 60)
 
 VARP (fullconsize, 0, 75, 100)
 
 HVARP (confilter, 0, 0x2CEF, 0x7FFFFFF)
 
 HVARP (fullconfilter, 0, 0x7FFFFFF, 0x7FFFFFF)
 
 HVARP (miniconfilter, 0, 0, 0x7FFFFFF)
 
void setconskip (int &skip, int filter, int n)
 
 ICOMMAND (clearconsole,"",(),{while(conlines.length()) delete[] conlines.pop().line;})
 
 ICOMMAND (conskip,"i",(int *n), setconskip(conskip, fullconsole?fullconfilter:confilter,*n))
 
 ICOMMAND (miniconskip,"i",(int *n), setconskip(miniconskip, miniconfilter,*n))
 
int drawconlines (int conskip, int confade, int conwidth, int conheight, int conoff, int filter, int y=0, int dir=1)
 
int renderconsole (int w, int h, int abovehud)
 
void keymap (int *code, char *key)
 
 COMMAND (keymap,"is")
 
const char * getkeyname (int code)
 
void searchbinds (char *action, int type)
 
keymfindbind (char *key)
 
void getbind (char *key, int type)
 
void bindkey (char *key, char *action, int state, const char *cmd)
 
 ICOMMAND (bind,"ss",(char *key, char *action), bindkey(key, action, keym::ACTION_DEFAULT,"bind"))
 
 ICOMMAND (editbind,"ss",(char *key, char *action), bindkey(key, action, keym::ACTION_EDITING,"editbind"))
 
 ICOMMAND (getbind,"s",(char *key), getbind(key, keym::ACTION_DEFAULT))
 
 ICOMMAND (geteditbind,"s",(char *key), getbind(key, keym::ACTION_EDITING))
 
 ICOMMAND (getspecbind,"s",(char *key), getbind(key, keym::ACTION_SPECTATOR))
 
 ICOMMAND (searchbinds,"s",(char *action), searchbinds(action, keym::ACTION_DEFAULT))
 
 ICOMMAND (searcheditbinds,"s",(char *action), searchbinds(action, keym::ACTION_EDITING))
 
 ICOMMAND (searchspecbinds,"s",(char *action), searchbinds(action, keym::ACTION_SPECTATOR))
 
 ICOMMAND (specbind,"ss",(char *key, char *action), bindkey(key, action, keym::ACTION_SPECTATOR,"specbind"))
 
void inputcommand (char *init, char *action=nullptr, char *prompt=nullptr, char *flags=nullptr)
 
 ICOMMAND (saycommand,"C",(char *init), inputcommand(init))
 
 COMMAND (inputcommand,"ssss")
 
void pasteconsole ()
 
 VARP (maxhistory, 0, 1000, 10000)
 
const char * historyfile ()
 
void writehistory ()
 
 COMMAND (writehistory,"")
 
void loadhistory ()
 
 COMMAND (loadhistory,"")
 
void history_ (int *n)
 
 COMMANDN (history, history_,"i")
 
const char * addreleaseaction (char *s)
 
void onrelease (const char *s)
 
 COMMAND (onrelease,"s")
 
void execbind (keym &k, bool isdown)
 
bool consoleinput (const char *str, int len)
 
bool consolekey (int code, bool isdown)
 
void processtextinput (const char *str, int len)
 
void processkey (int code, bool isdown)
 
void clear_console ()
 
void writebinds (stream *f)
 
static bool htcmp (const fileskey &x, const fileskey &y)
 
static uint hthash (const fileskey &k)
 
void resetcomplete ()
 
void addcomplete (char *command, int type, char *dir, char *ext)
 
void addfilecomplete (char *command, char *dir, char *ext)
 
void addlistcomplete (char *command, char *list)
 
 COMMANDN (complete, addfilecomplete,"sss")
 
 COMMANDN (listcomplete, addlistcomplete,"ss")
 
void complete (char *s, int maxlen, const char *cmdprefix, bool backwards=0)
 
void writecompletions (stream *f)
 

Variables

reversequeue< cline, MAXCONLINESconlines
 
int commandmillis = -1
 
string commandbuf
 
char * commandaction = nullptr
 
char * commandprompt = nullptr
 
int commandflags = 0
 
int commandpos = -1
 
std::set< std::stringwarningsDisplayed
 List of already displayed warnings, we only want to display them once. More...
 
int conskip = 0
 
int miniconskip = 0
 
hashtable< int, keymkeyms (128)
 
keymkeypressed = nullptr
 
char * keyaction = nullptr
 
vector< hline * > history
 
int histpos = 0
 
vector< releaseactionreleaseactions
 
static hashtable< fileskey,
filesval * > 
completefiles
 
static hashtable< char
*, filesval * > 
completions
 
int completesize = 0
 
char * lastcomplete = nullptr
 

Class Documentation

struct cline
Class Members
char * line
int outtime
int type
struct releaseaction
Class Members
char * action
keym * key

Macro Definition Documentation

#define CONSTRLEN   512

Referenced by conline().

#define MAXCONLINES   1000
#define MOD_KEYS   (KMOD_LCTRL|KMOD_RCTRL)

Referenced by consolekey().

Enumeration Type Documentation

anonymous enum
Enumerator
CF_COMPLETE 
CF_EXECUTE 
anonymous enum
Enumerator
FILES_DIR 
FILES_LIST 

Function Documentation

void addcomplete ( char *  command,
int  type,
char *  dir,
char *  ext 
)
void addfilecomplete ( char *  command,
char *  dir,
char *  ext 
)

References addcomplete(), and FILES_DIR.

void addlistcomplete ( char *  command,
char *  list 
)

References addcomplete(), and FILES_LIST.

const char* addreleaseaction ( char *  s)
void bindkey ( char *  key,
char *  action,
int  state,
const char *  cmd 
)
void clear_console ( )

References keyms.

Referenced by cleanup().

COMMAND ( keymap  ,
"is"   
)
COMMAND ( inputcommand  ,
"ssss"   
)
COMMAND ( writehistory  ,
""   
)
COMMAND ( loadhistory  ,
""   
)
COMMAND ( onrelease  ,
"s"   
)
COMMANDN ( history  ,
history_  ,
"i"   
)
COMMANDN ( complete  ,
addfilecomplete  ,
"sss"   
)
COMMANDN ( listcomplete  ,
addlistcomplete  ,
"ss"   
)
void complete ( char *  s,
int  maxlen,
const char *  cmdprefix,
bool  backwards = 0 
)
void conline ( int  type,
const char *  sf 
)

Function which displayes console text ingame. (legacy UI)

bool consoleinput ( const char *  str,
int  len 
)
bool consolekey ( int  code,
bool  isdown 
)
int drawconlines ( int  conskip,
int  confade,
int  conwidth,
int  conheight,
int  conoff,
int  filter,
int  y = 0,
int  dir = 1 
)
void execbind ( keym k,
bool  isdown 
)
keym* findbind ( char *  key)

References enumerate, and keyms.

Referenced by bindkey(), and getbind().

void getbind ( char *  key,
int  type 
)

References keym::actions, findbind(), and result().

const char* getkeyname ( int  code)

References keyms, and keym::name.

Referenced by g3d_key().

void history_ ( int *  n)

References history.

const char* historyfile ( )

Referenced by loadhistory(), and writehistory().

static bool htcmp ( const fileskey x,
const fileskey y 
)
inlinestatic
static uint hthash ( const fileskey k)
inlinestatic
HVARP ( confilter  ,
,
0x2CEF  ,
0x7FFFFFF   
)
HVARP ( fullconfilter  ,
,
0x7FFFFFF  ,
0x7FFFFFF   
)
HVARP ( miniconfilter  ,
,
,
0x7FFFFFF   
)
ICOMMAND ( toggleconsole  ,
""  ,
()  ,
{fullconsole^=1;}   
)
ICOMMAND ( clearconsole  ,
""  ,
()  ,
{while(conlines.length()) delete[] conlines.pop().line;}   
)
ICOMMAND ( conskip  ,
"i"  ,
(int *n)  ,
setconskip(conskip, fullconsole?fullconfilter:confilter,*n)   
)
ICOMMAND ( miniconskip  ,
"i"  ,
(int *n)  ,
setconskip(miniconskip, miniconfilter,*n)   
)
ICOMMAND ( bind  ,
"ss"  ,
(char *key, char *action)  ,
bindkey(key, action, keym::ACTION_DEFAULT,"bind")   
)
ICOMMAND ( editbind  ,
"ss"  ,
(char *key, char *action)  ,
bindkey(key, action, keym::ACTION_EDITING,"editbind")   
)
ICOMMAND ( getbind  ,
"s"  ,
(char *key)  ,
getbind(key, keym::ACTION_DEFAULT  
)
ICOMMAND ( geteditbind  ,
"s"  ,
(char *key)  ,
getbind(key, keym::ACTION_EDITING  
)
ICOMMAND ( getspecbind  ,
"s"  ,
(char *key)  ,
getbind(key, keym::ACTION_SPECTATOR  
)
ICOMMAND ( searchbinds  ,
"s"  ,
(char *action)  ,
searchbinds(action, keym::ACTION_DEFAULT  
)
ICOMMAND ( searcheditbinds  ,
"s"  ,
(char *action)  ,
searchbinds(action, keym::ACTION_EDITING  
)
ICOMMAND ( searchspecbinds  ,
"s"  ,
(char *action)  ,
searchbinds(action, keym::ACTION_SPECTATOR  
)
ICOMMAND ( specbind  ,
"ss"  ,
(char *key, char *action)  ,
bindkey(key, action, keym::ACTION_SPECTATOR,"specbind")   
)
ICOMMAND ( saycommand  ,
"C"  ,
(char *init)  ,
inputcommand(init)   
)
void inputcommand ( char *  init,
char *  action = nullptr,
char *  prompt = nullptr,
char *  flags = nullptr 
)
void keymap ( int *  code,
char *  key 
)
void loadhistory ( )
void onrelease ( const char *  s)

References addreleaseaction(), and newstring().

void pasteconsole ( )

References commandbuf, and decodeutf8().

Referenced by consolekey().

void processkey ( int  code,
bool  isdown 
)
void processtextinput ( const char *  str,
int  len 
)
int rendercommand ( int  x,
int  y,
int  w 
)
int renderconsole ( int  w,
int  h,
int  abovehud 
)
void resetcomplete ( )

References completesize.

Referenced by consoleinput(), and consolekey().

void searchbinds ( char *  action,
int  type 
)
void setconskip ( int &  skip,
int  filter,
int  n 
)

References conlines, and dir.

VAR ( fullconsole  ,
,
,
 
)
VARFP ( maxcon  ,
10  ,
200  ,
MAXCONLINES  ,
{while(conlines.length() > maxcon) delete[] conlines.pop().line;}   
)
VARP ( confading  ,
,
,
 
)
VARP ( consize  ,
,
,
100   
)
VARP ( miniconsize  ,
,
,
100   
)
VARP ( miniconwidth  ,
,
40  ,
100   
)
VARP ( confade  ,
,
30  ,
60   
)
VARP ( miniconfade  ,
,
30  ,
60   
)
VARP ( fullconsize  ,
,
75  ,
100   
)
VARP ( maxhistory  ,
,
1000  ,
10000   
)
void writebinds ( stream f)
void writecompletions ( stream f)
void writehistory ( )

Variable Documentation

char* commandaction = nullptr
string commandbuf
int commandflags = 0
int commandmillis = -1
int commandpos = -1
char * commandprompt = nullptr
hashtable<fileskey, filesval *> completefiles
static

Referenced by addcomplete().

int completesize = 0

Referenced by complete(), and resetcomplete().

hashtable<char *, filesval *> completions
static

Referenced by conline(), drawconlines(), and setconskip().

int conskip = 0

Referenced by renderconsole().

vector<hline *> history
int histpos = 0

Referenced by consolekey(), and loadhistory().

char* keyaction = nullptr

Referenced by bindkey(), and execbind().

hashtable<int, keym> keyms(128)
keym* keypressed = nullptr

Referenced by addreleaseaction(), bindkey(), and execbind().

char* lastcomplete = nullptr

Referenced by complete().

int miniconskip = 0

Referenced by renderconsole().

vector<releaseaction> releaseactions

Referenced by addreleaseaction(), and execbind().

std::set<std::string> warningsDisplayed

List of already displayed warnings, we only want to display them once.