Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Console.h
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2013-2019 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
23
24#pragma once
25
26#include "CVar.h"
27#include "ConsoleCmd.h"
28
29#include <Ogre.h>
30#include <string>
31#include <unordered_map>
32
33namespace RoR {
34
37
40class Console : public Ogre::LogListener
41{
42public:
43 typedef std::unordered_map<std::string, CVar*> CVarPtrMap;
44 typedef std::unordered_map<std::string, ConsoleCmd*> CommandPtrMap;
45
57
66
67 struct Message
68 {
69 Message(MessageArea area, MessageType type, std::string const& text,
70 size_t time, uint32_t net_user = 0, std::string icon = ""):
71 cm_area(area), cm_type(type), cm_text(text), cm_timestamp(time), cm_net_userid(net_user), cm_icon(icon)
72 {}
73
77 uint32_t cm_net_userid;
78 std::string cm_text;
79 std::string cm_icon;
80 };
81
83 {
85 : lock(console.m_messages_mutex), messages(console.m_messages)
86 {}
88 : MsgLockGuard(*console)
89 {}
90
91 std::vector<Message> & messages;
92 std::lock_guard<std::mutex> lock;
93 };
94
95 void putMessage(MessageArea area, MessageType type, std::string const& msg, std::string icon = "");
96 void putNetMessage(int user_id, MessageType type, const char* text);
97 void forwardLogMessage(MessageArea area, std::string const& msg, Ogre::LogMessageLevel lml);
98 unsigned long queryMessageTimer() { return m_msg_timer.getMilliseconds(); }
99 void purgeNetChatMessagesByUser(int user_id);
100
101 // ----------------------------
102 // Commands (defined in ConsoleCmd.cpp):
103
105 void regBuiltinCommands();
106
108 void doCommand(std::string msg);
109
110 // ----------------------------
111 // CVars (defined in CVar.cpp):
112
114 CVar* cVarCreate(std::string const& name, std::string const& long_name,
115 int flags, std::string const& val = std::string());
116
118 void cVarAssign(CVar* cvar, std::string const& value);
119
121 CVar* cVarFind(std::string const& input_name);
122
124 CVar* cVarSet(std::string const& input_name, std::string const& input_val);
125
127 CVar* cVarGet(std::string const& input_name, int flags);
128
130 void cVarSetupBuiltins();
131
133
135
136 // ----------------------------
137 // Command line (defined in AppCommandLine.cpp)
138
139 void processCommandLine(int argc, char *argv[]);
142
143 // ----------------------------
144 // Config file (defined in AppConfig.cpp)
145
146 void loadConfig();
147 void saveConfig();
148
149private:
150 // Ogre::LogListener
151 virtual void messageLogged(
152 const Ogre::String& message, Ogre::LogMessageLevel lml,
153 bool maskDebug, const Ogre::String& logName, bool& skipThisMessage) override;
154
155 void handleMessage(MessageArea area, MessageType type, std::string const& msg, int net_id = 0, std::string icon = "");
156
157 std::vector<Message> m_messages;
159 Ogre::Timer m_msg_timer;
163};
164
166
167} //namespace RoR
Quake-style console variable, defined in RoR.cfg or crated via Console UI and scripts.
Definition CVar.h:53
Global game console backend.
Definition Console.h:41
CVar * cVarSet(std::string const &input_name, std::string const &input_val)
Set existing cvar by short/long name. Return the modified cvar (or NULL if not found)
Definition CVar.cpp:284
void cVarAssign(CVar *cvar, std::string const &value)
Parse value by cvar type.
Definition CVar.cpp:249
CommandPtrMap & getCommands()
Definition Console.h:134
void putNetMessage(int user_id, MessageType type, const char *text)
Definition Console.cpp:108
virtual void messageLogged(const Ogre::String &message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool &skipThisMessage) override
Definition Console.cpp:32
void processCommandLine(int argc, char *argv[])
void showCommandLineUsage()
std::unordered_map< std::string, CVar * > CVarPtrMap
Definition Console.h:43
void saveConfig()
unsigned long queryMessageTimer()
Definition Console.h:98
std::mutex m_messages_mutex
Definition Console.h:158
std::vector< Message > m_messages
Definition Console.h:157
std::unordered_map< std::string, ConsoleCmd * > CommandPtrMap
Definition Console.h:44
CommandPtrMap m_commands
Definition Console.h:162
@ CONSOLE_MSGTYPE_ACTOR
Parsing/spawn/simulation messages for actors.
Definition Console.h:63
@ CONSOLE_MSGTYPE_SCRIPT
Messages sent from scripts.
Definition Console.h:62
@ CONSOLE_MSGTYPE_INFO
Generic message.
Definition Console.h:60
@ CONSOLE_MSGTYPE_TERRN
Parsing/spawn/simulation messages for terrain.
Definition Console.h:64
@ CONSOLE_MSGTYPE_LOG
Logfile echo.
Definition Console.h:61
void purgeNetChatMessagesByUser(int user_id)
Definition Console.cpp:58
CVar * cVarCreate(std::string const &name, std::string const &long_name, int flags, std::string const &val=std::string())
Add CVar and parse default value if specified.
Definition CVar.cpp:225
CVarPtrMap m_cvars
Definition Console.h:160
void cVarSetupBuiltins()
Create builtin vars and set defaults.
Definition CVar.cpp:29
Ogre::Timer m_msg_timer
Definition Console.h:159
void showCommandLineVersion()
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
Definition Console.cpp:103
CVar * cVarFind(std::string const &input_name)
Find cvar by short/long name.
Definition CVar.cpp:267
void handleMessage(MessageArea area, MessageType type, std::string const &msg, int net_id=0, std::string icon="")
Definition Console.cpp:64
void loadConfig()
@ CONSOLE_SYSTEM_ERROR
Definition Console.h:52
@ CONSOLE_SYSTEM_NOTICE
Definition Console.h:51
@ CONSOLE_SYSTEM_WARNING
Definition Console.h:53
@ CONSOLE_SYSTEM_REPLY
Success.
Definition Console.h:54
@ CONSOLE_SYSTEM_NETCHAT
Definition Console.h:55
@ CONSOLE_TITLE
Definition Console.h:49
CVarPtrMap m_cvars_longname
Definition Console.h:161
CVar * cVarGet(std::string const &input_name, int flags)
Get cvar by short/long name, or create new one using input as short name.
Definition CVar.cpp:295
CVarPtrMap & getCVars()
Definition Console.h:132
void forwardLogMessage(MessageArea area, std::string const &msg, Ogre::LogMessageLevel lml)
Definition Console.cpp:40
void regBuiltinCommands()
Register builtin commands.
void doCommand(std::string msg)
Identify and execute any console line.
std::string cm_icon
Definition Console.h:79
Message(MessageArea area, MessageType type, std::string const &text, size_t time, uint32_t net_user=0, std::string icon="")
Definition Console.h:69
MessageType cm_type
Definition Console.h:75
uint32_t cm_net_userid
Definition Console.h:77
std::string cm_text
Definition Console.h:78
MessageArea cm_area
Definition Console.h:74
std::vector< Message > & messages
Definition Console.h:91
MsgLockGuard(Console &console)
Definition Console.h:84
MsgLockGuard(Console *console)
Definition Console.h:87
std::lock_guard< std::mutex > lock
Definition Console.h:92