HoverRace  2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
HoverRace::Client::HoverScript::SysConsole Class Reference

Global always-on console. More...

#include <SysConsole.h>

+ Inheritance diagram for HoverRace::Client::HoverScript::SysConsole:

Classes

struct  LogLine
 

Public Types

using logAddedSignal_t = boost::signals2::signal< void(size_t)>
 Fired when a log line is added. Parameter is the log index. More...
 
using logClearedSignal_t = boost::signals2::signal< void()>
 Fired when the log is cleared. More...
 
enum  LogLevel { LogLevel::HISTORY, LogLevel::NOTE, LogLevel::INFO, LogLevel::ERROR }
 
- Public Types inherited from HoverRace::Client::HoverScript::Console
enum  InputState { InputState::COMMAND, InputState::CONTINUE }
 

Public Member Functions

 SysConsole (Script::Core &scripting, GameDirector &director, DebugPeer &debugPeer, GamePeer &gamePeer, InputPeer &inputPeer, size_t maxLogLines=512, size_t maxHistory=64)
 Constructor. More...
 
virtual ~SysConsole ()
 
void AddIntroLines ()
 Add the introductory text to the log. More...
 
void Advance (Util::OS::timestamp_t tick) override
 
void Clear () override
 Clear the console. More...
 
std::string & GetCommandLine ()
 
int GetEndLogIndex () const
 Retrieve the index of the last log entry. More...
 
logAddedSignal_tGetLogAddedSignal ()
 
logClearedSignal_tGetLogClearedSignal ()
 
void HelpClass (const Script::Help::Class &cls) override
 
void HelpMethod (const Script::Help::Class &cls, const Script::Help::Method &method) override
 
void LoadNextCmd ()
 Replace the command line with the next command from the history. More...
 
void LoadPrevCmd ()
 Replace the command line with the previous command from the history. More...
 
void LogError (const std::string &s) override
 
void LogHistory (const std::string &s)
 
void LogInfo (const std::string &s) override
 
void LogNote (const std::string &s)
 
template<class Function >
void ReadLogs (Function fn)
 Read all log entries. More...
 
template<class Function >
void ReadLogs (size_t start, Function fn)
 Read a subset of log entries, from a starting index to the end. More...
 
template<class Function >
void ReadLogs (size_t start, size_t end, Function fn)
 Read a subset of log entries, for a specific range. More...
 
void SubmitChunkWithHistory (const std::string &s)
 Submit a chunk to the script engine and store it in the history. More...
 
- Public Member Functions inherited from HoverRace::Client::HoverScript::Console
 Console (Script::Core &scripting)
 
virtual ~Console ()
 
InputState GetInputState () const
 
void SubmitChunk (const std::string &s)
 Submit a chunk to the script engine. More...
 
- Public Member Functions inherited from HoverRace::Script::Env
 Env (Core &scripting)
 Constructor. More...
 
 Env (const Env &)=delete
 
virtual ~Env ()
 
Envoperator= (const Env &)=delete
 
bool RunScript (const Util::OS::path_t &filename)
 Execute a script from a file. More...
 

Static Public Member Functions

static int LQuit (lua_State *L)
 

Protected Member Functions

void InitEnv () override
 Initialize the environment in which scripts will run in. More...
 
- Protected Member Functions inherited from HoverRace::Client::HoverScript::Console
void SetInputState (InputState newState)
 
- Protected Member Functions inherited from HoverRace::Script::Env
void CopyGlobals ()
 Copy the global environment into the current table at the top of the stack. More...
 
template<class ReturnPolicy = Core::PrintReturn>
int Execute (const Core::Chunk &chunk, ReturnPolicy rp=ReturnPolicy())
 Execute a chunk of code in the current environment. More...
 
CoreGetScripting () const
 
lua_State * GetState () const
 
void LogScriptError (const Script::ScriptExn &ex)
 
void PushEnv ()
 Push the environment onto the stack. More...
 
void SetHelpHandler (Help::HelpHandler *helpHandler)
 

Private Types

using history_t = boost::circular_buffer< std::string >
 
using SUPER = Console
 

Private Member Functions

void AddLogLine (LogLevel level, const std::string &line)
 
void OnLog (const Util::Log::Entry &entry)
 
void OnSessionChanged (std::shared_ptr< MetaSession > metaSession)
 

Private Attributes

size_t baseLogIdx
 Index of the first item in logLines. More...
 
std::string commandLine
 
history_t::iterator curHistory
 
DebugPeerdebugPeer
 
GameDirectordirector
 
GamePeergamePeer
 
history_t history
 
InputPeerinputPeer
 
bool introWritten
 
logAddedSignal_t logAddedSignal
 
logClearedSignal_t logClearedSignal
 
boost::signals2::scoped_connection logConn
 
std::deque< LogLinelogLines
 
size_t maxLogLines
 
std::shared_ptr< MetaSessionmetaSession
 
boost::signals2::scoped_connection sessionChangedConn
 

Additional Inherited Members

- Static Protected Member Functions inherited from HoverRace::Script::Env
static Core::Chunk LoadChunkFromFile (const Util::OS::path_t &filename)
 Load a chunk from a file. More...
 

Detailed Description

Global always-on console.

This is the backend for the ConsoleScene, allowing it to maintain state between instances.

Author
Michael Imamura

Member Typedef Documentation

using HoverRace::Client::HoverScript::SysConsole::history_t = boost::circular_buffer<std::string>
private
using HoverRace::Client::HoverScript::SysConsole::logAddedSignal_t = boost::signals2::signal<void(size_t)>

Fired when a log line is added. Parameter is the log index.

using HoverRace::Client::HoverScript::SysConsole::logClearedSignal_t = boost::signals2::signal<void()>

Fired when the log is cleared.

Member Enumeration Documentation

Enumerator
HISTORY 
NOTE 
INFO 
ERROR 

Constructor & Destructor Documentation

HoverRace::Client::HoverScript::SysConsole::SysConsole ( Script::Core scripting,
GameDirector director,
DebugPeer debugPeer,
GamePeer gamePeer,
InputPeer inputPeer,
size_t  maxLogLines = 512,
size_t  maxHistory = 64 
)

Constructor.

Parameters
scriptingThe underlying scripting engine.
directorThe game director.
debugPeerDebug scripting peer.
gamePeerGame scripting peer.
inputPeerInput scripting peer.
maxLogLinesThe maximum number of log lines to store in the log history.
maxHistoryThe maximum number of commands to keep in the history.
HoverRace::Client::HoverScript::SysConsole::~SysConsole ( )
virtual

Member Function Documentation

void HoverRace::Client::HoverScript::SysConsole::AddIntroLines ( )

Add the introductory text to the log.

The text is only written once; after that, this function has no effect. The idea is that we wait until the console is first visible before writing the intro text – otherwise, the intro text will get lost in the sea of other log entries.

void HoverRace::Client::HoverScript::SysConsole::AddLogLine ( LogLevel  level,
const std::string &  line 
)
private
void HoverRace::Client::HoverScript::SysConsole::Advance ( Util::OS::timestamp_t  tick)
inlineoverridevirtual
void HoverRace::Client::HoverScript::SysConsole::Clear ( )
overridevirtual

Clear the console.

Implements HoverRace::Client::HoverScript::Console.

std::string& HoverRace::Client::HoverScript::SysConsole::GetCommandLine ( )
inline
int HoverRace::Client::HoverScript::SysConsole::GetEndLogIndex ( ) const

Retrieve the index of the last log entry.

Returns
The index or -1 if the log has been cleared.
logAddedSignal_t& HoverRace::Client::HoverScript::SysConsole::GetLogAddedSignal ( )
inline
logClearedSignal_t& HoverRace::Client::HoverScript::SysConsole::GetLogClearedSignal ( )
inline
void HoverRace::Client::HoverScript::SysConsole::HelpClass ( const Script::Help::Class cls)
overridevirtual
void HoverRace::Client::HoverScript::SysConsole::HelpMethod ( const Script::Help::Class cls,
const Script::Help::Method method 
)
overridevirtual
void HoverRace::Client::HoverScript::SysConsole::InitEnv ( )
overrideprotectedvirtual

Initialize the environment in which scripts will run in.

Upon entry, the Lua stack will have at least one entry, the table which represents the environment. Implementing functions will fill this table with the globals which will be available to the functions which are run in this environment. Upon return, this same table must be at the top of the stack.

Reimplemented from HoverRace::Client::HoverScript::Console.

void HoverRace::Client::HoverScript::SysConsole::LoadNextCmd ( )

Replace the command line with the next command from the history.

void HoverRace::Client::HoverScript::SysConsole::LoadPrevCmd ( )

Replace the command line with the previous command from the history.

void HoverRace::Client::HoverScript::SysConsole::LogError ( const std::string &  s)
overridevirtual
void HoverRace::Client::HoverScript::SysConsole::LogHistory ( const std::string &  s)
void HoverRace::Client::HoverScript::SysConsole::LogInfo ( const std::string &  s)
overridevirtual
void HoverRace::Client::HoverScript::SysConsole::LogNote ( const std::string &  s)
int HoverRace::Client::HoverScript::SysConsole::LQuit ( lua_State *  L)
static
void HoverRace::Client::HoverScript::SysConsole::OnLog ( const Util::Log::Entry entry)
private
void HoverRace::Client::HoverScript::SysConsole::OnSessionChanged ( std::shared_ptr< MetaSession metaSession)
private
template<class Function >
void HoverRace::Client::HoverScript::SysConsole::ReadLogs ( Function  fn)
inline

Read all log entries.

Parameters
fnThe callback function (will be passed a LogLine reference).
template<class Function >
void HoverRace::Client::HoverScript::SysConsole::ReadLogs ( size_t  start,
Function  fn 
)
inline

Read a subset of log entries, from a starting index to the end.

Parameters
startThe starting log index (inclusive).
fnThe callback function (will be passed a LogLine reference).
template<class Function >
void HoverRace::Client::HoverScript::SysConsole::ReadLogs ( size_t  start,
size_t  end,
Function  fn 
)
inline

Read a subset of log entries, for a specific range.

Parameters
startThe starting log index (inclusive).
endThe ending log index (inclusive).
fnThe callback function (will be passed a LogLine reference).
void HoverRace::Client::HoverScript::SysConsole::SubmitChunkWithHistory ( const std::string &  s)

Submit a chunk to the script engine and store it in the history.

Empty chunks are not saved to the history.

Parameters
sThe chunk.

Member Data Documentation

size_t HoverRace::Client::HoverScript::SysConsole::baseLogIdx
private

Index of the first item in logLines.

std::string HoverRace::Client::HoverScript::SysConsole::commandLine
private
history_t::iterator HoverRace::Client::HoverScript::SysConsole::curHistory
private
DebugPeer& HoverRace::Client::HoverScript::SysConsole::debugPeer
private
GameDirector& HoverRace::Client::HoverScript::SysConsole::director
private
GamePeer& HoverRace::Client::HoverScript::SysConsole::gamePeer
private
history_t HoverRace::Client::HoverScript::SysConsole::history
private
InputPeer& HoverRace::Client::HoverScript::SysConsole::inputPeer
private
bool HoverRace::Client::HoverScript::SysConsole::introWritten
private
logAddedSignal_t HoverRace::Client::HoverScript::SysConsole::logAddedSignal
private
logClearedSignal_t HoverRace::Client::HoverScript::SysConsole::logClearedSignal
private
boost::signals2::scoped_connection HoverRace::Client::HoverScript::SysConsole::logConn
private
std::deque<LogLine> HoverRace::Client::HoverScript::SysConsole::logLines
private
size_t HoverRace::Client::HoverScript::SysConsole::maxLogLines
private
std::shared_ptr<MetaSession> HoverRace::Client::HoverScript::SysConsole::metaSession
private
boost::signals2::scoped_connection HoverRace::Client::HoverScript::SysConsole::sessionChangedConn
private

The documentation for this class was generated from the following files: