HoverRace
2.0
|
Global always-on console. More...
#include <SysConsole.h>
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_t & | GetLogAddedSignal () |
logClearedSignal_t & | GetLogClearedSignal () |
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 () |
Env & | operator= (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... | |
Core & | GetScripting () 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 |
DebugPeer & | debugPeer |
GameDirector & | director |
GamePeer & | gamePeer |
history_t | history |
InputPeer & | inputPeer |
bool | introWritten |
logAddedSignal_t | logAddedSignal |
logClearedSignal_t | logClearedSignal |
boost::signals2::scoped_connection | logConn |
std::deque< LogLine > | logLines |
size_t | maxLogLines |
std::shared_ptr< MetaSession > | metaSession |
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... | |
Global always-on console.
This is the backend for the ConsoleScene, allowing it to maintain state between instances.
|
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.
|
private |
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.
scripting | The underlying scripting engine. |
director | The game director. |
debugPeer | Debug scripting peer. |
gamePeer | Game scripting peer. |
inputPeer | Input scripting peer. |
maxLogLines | The maximum number of log lines to store in the log history. |
maxHistory | The maximum number of commands to keep in the history. |
|
virtual |
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.
|
private |
|
inlineoverridevirtual |
Implements HoverRace::Client::HoverScript::Console.
|
overridevirtual |
Clear the console.
Implements HoverRace::Client::HoverScript::Console.
|
inline |
int HoverRace::Client::HoverScript::SysConsole::GetEndLogIndex | ( | ) | const |
Retrieve the index of the last log entry.
|
inline |
|
inline |
|
overridevirtual |
Implements HoverRace::Script::Help::HelpHandler.
|
overridevirtual |
Implements HoverRace::Script::Help::HelpHandler.
|
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.
|
overridevirtual |
Implements HoverRace::Client::HoverScript::Console.
void HoverRace::Client::HoverScript::SysConsole::LogHistory | ( | const std::string & | s | ) |
|
overridevirtual |
Implements HoverRace::Client::HoverScript::Console.
void HoverRace::Client::HoverScript::SysConsole::LogNote | ( | const std::string & | s | ) |
|
static |
|
private |
|
private |
|
inline |
Read all log entries.
fn | The callback function (will be passed a LogLine reference). |
|
inline |
Read a subset of log entries, from a starting index to the end.
start | The starting log index (inclusive). |
fn | The callback function (will be passed a LogLine reference). |
|
inline |
Read a subset of log entries, for a specific range.
start | The starting log index (inclusive). |
end | The ending log index (inclusive). |
fn | The 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.
s | The chunk. |
|
private |
Index of the first item in logLines.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |