Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AngelScript: added console + cvars #2788

Merged
merged 4 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions doc/angelscript/CVarClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

/**
* @brief Types and special attributes of cvars.
* @note Default cvar type is string - To create a string cvar, enter '0' as flags.
*/
enum CVarFlags
{
CVAR_TYPE_BOOL = BITMASK(1),
CVAR_TYPE_INT = BITMASK(2),
CVAR_TYPE_FLOAT = BITMASK(3),
CVAR_ARCHIVE = BITMASK(4), //!< Will be written to RoR.cfg
CVAR_NO_LOG = BITMASK(5) //!< Will not be written to RoR.log
};

/**
* @brief A console variable, usually defined in RoR.cfg but also created by users or scripts.
*/
class CVarClass
{
public:

/**
* @brief Get the value converted to string, works with any CVAR_TYPE.
*/
std::string const& getStr() const { return m_value_str; }

float getFloat() const { return m_value_num; }

int getInt() const { return (int)m_value_num; }

bool getBool() const { return (bool)m_value_num; }

std::string const& getName() const { return m_name; }
};
35 changes: 35 additions & 0 deletions doc/angelscript/ConsoleClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@


/**
* @brief A class that gives you access to console variables (cvars), usually defined in RoR.cfg file.
* @note This object is created automatically as global variable `console`.
*/
class ConsoleClass
{
public:
/**
* @brief Add CVar and parse default value if specified
*/
CVar* cVarCreate(std::string const& name, std::string const& long_name,
int flags, std::string const& val = std::string());

/**
* Parse value by cvar type
*/
void cVarAssign(CVar* cvar, std::string const& value);

/**
* Find cvar by short/long name
*/
CVar* cVarFind(std::string const& input_name);

/**
* Set existing cvar by short/long name. Return the modified cvar (or NULL if not found)
*/
CVar* cVarSet(std::string const& input_name, std::string const& input_val);

/**
* Get cvar by short/long name, or create new one using input as short name.
*/
CVar* cVarGet(std::string const& input_name, int flags);
};
24 changes: 0 additions & 24 deletions doc/angelscript/SettingsClass.h

This file was deleted.

66 changes: 33 additions & 33 deletions source/main/AppContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool AppContext::SetUpInput()
App::GetInputEngine()->SetKeyboardListener(this);
App::GetInputEngine()->SetJoystickListener(this);

if (App::io_ffb_enabled->GetBool())
if (App::io_ffb_enabled->getBool())
{
m_force_feedback.Setup();
}
Expand Down Expand Up @@ -110,7 +110,7 @@ bool AppContext::mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID _id
handled = App::GetOverlayWrapper()->mousePressed(arg, _id); // update the old airplane / autopilot gui
}

if (!handled && App::app_state->GetEnum<AppState>() == AppState::SIMULATION)
if (!handled && App::app_state->getEnum<AppState>() == AppState::SIMULATION)
{
App::GetGameContext()->GetSceneMouse().mousePressed(arg, _id);
App::GetCameraManager()->mousePressed(arg, _id);
Expand All @@ -136,7 +136,7 @@ bool AppContext::mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID _i
{
handled = App::GetOverlayWrapper()->mouseReleased(arg, _id); // update the old airplane / autopilot gui
}
if (!handled && App::app_state->GetEnum<AppState>() == AppState::SIMULATION)
if (!handled && App::app_state->getEnum<AppState>() == AppState::SIMULATION)
{
App::GetGameContext()->GetSceneMouse().mouseReleased(arg, _id);
}
Expand Down Expand Up @@ -190,7 +190,7 @@ void AppContext::windowResized(Ogre::RenderWindow* rw)
{
App::GetInputEngine()->windowResized(rw); // Update mouse area
App::GetOverlayWrapper()->windowResized();
if (App::sim_state->GetEnum<AppState>() == RoR::AppState::SIMULATION)
if (App::sim_state->getEnum<AppState>() == RoR::AppState::SIMULATION)
{
for (Actor* actor: App::GetGameContext()->GetActorManager()->GetActors())
{
Expand Down Expand Up @@ -229,21 +229,21 @@ void AppContext::SetRenderWindowIcon(Ogre::RenderWindow* rw)
bool AppContext::SetUpRendering()
{
// Create 'OGRE root' facade
std::string log_filepath = PathCombine(App::sys_logs_dir->GetStr(), "RoR.log");
std::string cfg_filepath = PathCombine(App::sys_config_dir->GetStr(), "ogre.cfg");
std::string log_filepath = PathCombine(App::sys_logs_dir->getStr(), "RoR.log");
std::string cfg_filepath = PathCombine(App::sys_config_dir->getStr(), "ogre.cfg");
m_ogre_root = new Ogre::Root("", cfg_filepath, log_filepath);

// load OGRE plugins manually
#ifdef _DEBUG
std::string plugins_path = PathCombine(RoR::App::sys_process_dir->GetStr(), "plugins_d.cfg");
std::string plugins_path = PathCombine(RoR::App::sys_process_dir->getStr(), "plugins_d.cfg");
#else
std::string plugins_path = PathCombine(RoR::App::sys_process_dir->GetStr(), "plugins.cfg");
std::string plugins_path = PathCombine(RoR::App::sys_process_dir->getStr(), "plugins.cfg");
#endif
try
{
Ogre::ConfigFile cfg;
cfg.load(plugins_path);
std::string plugin_dir = cfg.getSetting("PluginFolder", /*section=*/"", /*default=*/App::sys_process_dir->GetStr());
std::string plugin_dir = cfg.getSetting("PluginFolder", /*section=*/"", /*default=*/App::sys_process_dir->getStr());
Ogre::StringVector plugins = cfg.getMultiSetting("Plugin");
for (Ogre::String plugin_filename: plugins)
{
Expand All @@ -270,14 +270,14 @@ bool AppContext::SetUpRendering()
ErrorUtils::ShowError (_L("Startup error"), _L("No render system plugin available. Check your plugins.cfg"));
}

const auto rs = m_ogre_root->getRenderSystemByName(App::app_rendersys_override->GetStr());
const auto rs = m_ogre_root->getRenderSystemByName(App::app_rendersys_override->getStr());
if (rs != nullptr && rs != m_ogre_root->getRenderSystem())
{
// The user has selected a different render system during the previous session.
m_ogre_root->setRenderSystem(rs);
m_ogre_root->saveConfig();
}
App::app_rendersys_override->SetStr("");
App::app_rendersys_override->setStr("");

// Start the renderer
m_ogre_root->initialise(/*createWindow=*/false);
Expand Down Expand Up @@ -341,30 +341,30 @@ void AppContext::CaptureScreenshot()

std::stringstream stamp;
stamp << std::put_time(std::localtime(&time), "%Y-%m-%d_%H-%M-%S") << "_" << index
<< "." << App::app_screenshot_format->GetStr();
std::string path = PathCombine(App::sys_screenshot_dir->GetStr(), "screenshot_") + stamp.str();
<< "." << App::app_screenshot_format->getStr();
std::string path = PathCombine(App::sys_screenshot_dir->getStr(), "screenshot_") + stamp.str();

if (App::app_screenshot_format->GetStr() == "png")
if (App::app_screenshot_format->getStr() == "png")
{
AdvancedScreen png(m_render_window, path);

png.addData("User_NickName", App::mp_player_name->GetStr());
png.addData("User_Language", App::app_language->GetStr());
png.addData("User_NickName", App::mp_player_name->getStr());
png.addData("User_Language", App::app_language->getStr());

if (App::app_state->GetEnum<AppState>() == AppState::SIMULATION &&
if (App::app_state->getEnum<AppState>() == AppState::SIMULATION &&
App::GetGameContext()->GetPlayerActor())
{
png.addData("Truck_file", App::GetGameContext()->GetPlayerActor()->ar_filename);
png.addData("Truck_name", App::GetGameContext()->GetPlayerActor()->getTruckName());
}
if (App::GetSimTerrain())
{
png.addData("Terrn_file", App::sim_terrain_name->GetStr());
png.addData("Terrn_name", App::sim_terrain_gui_name->GetStr());
png.addData("Terrn_file", App::sim_terrain_name->getStr());
png.addData("Terrn_name", App::sim_terrain_gui_name->getStr());
}
if (App::mp_state->GetEnum<MpState>() == MpState::CONNECTED)
if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED)
{
png.addData("MP_ServerName", App::mp_server_host->GetStr());
png.addData("MP_ServerName", App::mp_server_host->getStr());
}

png.write();
Expand Down Expand Up @@ -408,14 +408,14 @@ bool AppContext::SetUpProgramPaths()
ErrorUtils::ShowError(_L("Startup error"), _L("Error while retrieving program directory path"));
return false;
}
App::sys_process_dir->SetStr(RoR::GetParentDirectory(exe_path.c_str()).c_str());
App::sys_process_dir->setStr(RoR::GetParentDirectory(exe_path.c_str()).c_str());

// RoR's home directory
std::string local_userdir = PathCombine(App::sys_process_dir->GetStr(), "config"); // TODO: Think of a better name, this is ambiguious with ~/.rigsofrods/config which stores configfiles! ~ only_a_ptr, 02/2018
std::string local_userdir = PathCombine(App::sys_process_dir->getStr(), "config"); // TODO: Think of a better name, this is ambiguious with ~/.rigsofrods/config which stores configfiles! ~ only_a_ptr, 02/2018
if (FolderExists(local_userdir))
{
// It's a portable installation
App::sys_user_dir->SetStr(local_userdir.c_str());
App::sys_user_dir->setStr(local_userdir.c_str());
}
else
{
Expand All @@ -441,17 +441,17 @@ bool AppContext::SetUpProgramPaths()
ror_homedir << user_home << PATH_SLASH << "RigsOfRods";
#endif
CreateFolder(ror_homedir.ToCStr ());
App::sys_user_dir->SetStr(ror_homedir.ToCStr ());
App::sys_user_dir->setStr(ror_homedir.ToCStr ());
}

return true;
}

void AppContext::SetUpLogging()
{
std::string logs_dir = PathCombine(App::sys_user_dir->GetStr(), "logs");
std::string logs_dir = PathCombine(App::sys_user_dir->getStr(), "logs");
CreateFolder(logs_dir);
App::sys_logs_dir->SetStr(logs_dir.c_str());
App::sys_logs_dir->setStr(logs_dir.c_str());

auto ogre_log_manager = OGRE_NEW Ogre::LogManager();
std::string rorlog_path = PathCombine(logs_dir, "RoR.log");
Expand All @@ -465,7 +465,7 @@ void AppContext::SetUpLogging()

bool AppContext::SetUpResourcesDir()
{
std::string process_dir = PathCombine(App::sys_process_dir->GetStr(), "resources");
std::string process_dir = PathCombine(App::sys_process_dir->getStr(), "resources");
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
if (!FolderExists(process_dir))
{
Expand All @@ -477,21 +477,21 @@ bool AppContext::SetUpResourcesDir()
ErrorUtils::ShowError(_L("Startup error"), _L("Resources folder not found. Check if correctly installed."));
return false;
}
App::sys_resources_dir->SetStr(process_dir);
App::sys_resources_dir->setStr(process_dir);
return true;
}

bool AppContext::SetUpConfigSkeleton()
{
Ogre::String src_path = PathCombine(App::sys_resources_dir->GetStr(), "skeleton.zip");
Ogre::String src_path = PathCombine(App::sys_resources_dir->getStr(), "skeleton.zip");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(src_path, "Zip", "SrcRG");
Ogre::FileInfoListPtr fl = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo("SrcRG", "*", true);
if (fl->empty())
{
ErrorUtils::ShowError(_L("Startup error"), _L("Faulty resource folder. Check if correctly installed."));
return false;
}
Ogre::String dst_path = PathCombine(App::sys_user_dir->GetStr(), "");
Ogre::String dst_path = PathCombine(App::sys_user_dir->getStr(), "");
for (auto file : *fl)
{
CreateFolder(dst_path + file.basename);
Expand Down Expand Up @@ -533,7 +533,7 @@ void AppContext::SetUpObsoleteConfMarker()
{
if (!FileExists(Ogre::StringUtil::format("%s\\OBSOLETE_FOLDER.txt", old_ror_homedir.c_str())))
{
Ogre::String obsoleteMessage = Ogre::StringUtil::format("This folder is obsolete, please move your mods to %s", App::sys_user_dir->GetStr());
Ogre::String obsoleteMessage = Ogre::StringUtil::format("This folder is obsolete, please move your mods to %s", App::sys_user_dir->getStr());
try
{
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(old_ror_homedir, "FileSystem", "homedir", false, false);
Expand All @@ -548,7 +548,7 @@ void AppContext::SetUpObsoleteConfMarker()
Ogre::String message = Ogre::StringUtil::format(
"Welcome to Rigs of Rods %s\nPlease note that the mods folder has moved to:\n\"%s\"\nPlease move your mods to the new folder to continue using them",
ROR_VERSION_STRING_SHORT,
App::sys_user_dir->GetStr()
App::sys_user_dir->getStr()
);

RoR::App::GetGuiManager()->ShowMessageBox("Obsolete folder detected", message.c_str());
Expand Down
Loading