From ed30bca23e036158c9e12d123a179b9dc447fd60 Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Wed, 3 Mar 2021 16:08:22 +0530 Subject: [PATCH 1/3] Check for settings.json in launch folder as well --- Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp | 12 +++++++++--- Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.h | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp index 3e1551dab7..7f013ffabc 100644 --- a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp +++ b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp @@ -354,7 +354,12 @@ void ASimHUD::initializeSubWindows() } - +FString ASimHUD::getLaunchPath(const std::string& filename) +{ + FString launch_rel_path = FPaths::LaunchDir(); + FString abs_path = FPaths::ConvertRelativePathToFull(launch_rel_path); + return FPaths::Combine(abs_path, FString(filename.c_str()) ); +} // Attempts to parse the settings text from one of multiple locations. // First, check the command line for settings provided via "-s" or "--settings" arguments @@ -368,6 +373,8 @@ bool ASimHUD::getSettingsText(std::string& settingsText) || readSettingsTextFromFile(FString(msr::airlib::Settings::getExecutableFullPath("settings.json").c_str()), settingsText) || + readSettingsTextFromFile(getLaunchPath("settings.json"), settingsText) + || readSettingsTextFromFile(FString(msr::airlib::Settings::Settings::getUserDirectoryFullPath("settings.json").c_str()), settingsText)); } @@ -401,9 +408,8 @@ bool ASimHUD::getSettingsTextFromCommandLine(std::string& settingsText) return found; } -bool ASimHUD::readSettingsTextFromFile(FString settingsFilepath, std::string& settingsText) +bool ASimHUD::readSettingsTextFromFile(const FString& settingsFilepath, std::string& settingsText) { - bool found = FPaths::FileExists(settingsFilepath); if (found) { FString settingsTextFStr; diff --git a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.h b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.h index fab7fdf82f..beca5004db 100644 --- a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.h +++ b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.h @@ -67,9 +67,11 @@ class AIRSIM_API ASimHUD : public AHUD bool getSettingsText(std::string& settingsText); bool getSettingsTextFromCommandLine(std::string& settingsText); - bool readSettingsTextFromFile(FString fileName, std::string& settingsText); + bool readSettingsTextFromFile(const FString& fileName, std::string& settingsText); std::string getSimModeFromUser(); + static FString getLaunchPath(const std::string& filename); + private: typedef common_utils::Utils Utils; UClass* widget_class_; From 577428751cb581592673b42dbfc075fe450252b8 Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Tue, 23 Mar 2021 17:16:04 +0530 Subject: [PATCH 2/3] Docs: Update settings page with search locations for settings.json --- docs/settings.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/settings.md b/docs/settings.md index 800691ed3d..64fcded724 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -1,16 +1,27 @@ # AirSim Settings ## Where are Settings Stored? -AirSim is searching for the settings definition in 4 different ways in the following order. The first match will be used: +AirSim is searching for the settings definition in the following order. The first match will be used: -1. Looking at the (absolute) path specified by the `--settings` command line argument. -For example, in Windows: `AirSim.exe --settings 'C:\path\to\settings.json'` +1. Looking at the (absolute) path specified by the `--settings` command line argument. +For example, in Windows: `AirSim.exe --settings 'C:\path\to\settings.json'` In Linux `./Blocks.sh --settings '/home/$USER/path/to/settings.json'` -1. Looking for a json document passed as a command line argument by the `--settings` argument. -For example, in Windows: `AirSim.exe --settings '{"foo" : "bar"}'` + +2. Looking for a json document passed as a command line argument by the `--settings` argument. +For example, in Windows: `AirSim.exe --settings '{"foo" : "bar"}'` In Linux `./Blocks.sh --settings '{"foo" : "bar"}'` -1. Looking in the folder of the executable for a file called `settings.json`. -2. Looking in the users home folder for a file called `settings.json`. The AirSim subfolder is located at `Documents\AirSim` on Windows and `~/Documents/AirSim` on Linux systems. + +3. Looking in the folder of the executable for a file called `settings.json`. +This will be a deep location where the actual executable of the Editor or binary is stored. +For e.g. with the Blocks binary, the location searched is `/LinuxNoEditor/Blocks/Binaries/Linux/settings.json`. + +4. Searching for `settings.json` in the folder from where the executable is launched + + This is a top-level directory containing the launch script or executable. For e.g. Linux: `/LinuxNoEditor/settings.json`, Windows: `/WindowsNoEditor/settings.json` + + Note that this path changes depending on where its invoked from. On Linux, if executing the `Blocks.sh` script from inside LinuxNoEditor folder like `./Blocks.sh`, then the previous mentioned path is used. However, if launched from outside LinuxNoEditor folder such as `./LinuxNoEditor/Blocks.sh`, then `/settings.json` will be used. + +5. Looking in the AirSim subfolder for a file called `settings.json`. The AirSim subfolder is located at `Documents\AirSim` on Windows and `~/Documents/AirSim` on Linux systems. The file is in usual [json format](https://en.wikipedia.org/wiki/JSON). On first startup AirSim would create `settings.json` file with no settings at the users home folder. To avoid problems, always use ASCII format to save json file. From 728f68841991c4c7d56d8277af38da630ba3dfdf Mon Sep 17 00:00:00 2001 From: zimmy87 Date: Fri, 4 Jun 2021 06:24:25 -0700 Subject: [PATCH 3/3] apply style from clang-format --- .../Plugins/AirSim/Source/SimHUD/SimHUD.cpp | 57 +++++++++---------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp index 7f013ffabc..94f3500d07 100644 --- a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp +++ b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp @@ -10,7 +10,6 @@ #include "common/AirSimSettings.hpp" #include - ASimHUD::ASimHUD() { static ConstructorHelpers::FClassFinder hud_widget_class(TEXT("WidgetBlueprint'/AirSim/Blueprints/BP_SimHUDWidget'")); @@ -138,9 +137,8 @@ void ASimHUD::updateWidgetSubwindowVisibility() camera->setCameraTypeEnabled(camera_type, is_visible); widget_->setSubwindowVisibility(window_index, - is_visible, - is_visible ? camera->getRenderTarget(camera_type, false) : nullptr - ); + is_visible, + is_visible ? camera->getRenderTarget(camera_type, false) : nullptr); } } @@ -189,7 +187,6 @@ void ASimHUD::createMainWidget() UAirBlueprintLib::LogMessage(TEXT("There were no compatible vehicles created for current SimMode! Check your settings.json."), TEXT(""), LogDebugLevel::Failure); } - widget_ = CreateWidget(player_controller, widget_class_); } else { @@ -210,7 +207,6 @@ void ASimHUD::createMainWidget() updateWidgetSubwindowVisibility(); } - void ASimHUD::setUnrealEngineSettings() { //TODO: should we only do below on SceneCapture2D components and cameras? @@ -275,9 +271,8 @@ std::vector& ASimHUD::getSubWindowSet std::string ASimHUD::getSimModeFromUser() { if (EAppReturnType::No == UAirBlueprintLib::ShowMessage(EAppMsgType::YesNo, - "Would you like to use car simulation? Choose no to use quadrotor simulation.", - "Choose Vehicle")) - { + "Would you like to use car simulation? Choose no to use quadrotor simulation.", + "Choose Vehicle")) { return AirSimSettings::kSimModeTypeMultirotor; } else @@ -287,9 +282,9 @@ std::string ASimHUD::getSimModeFromUser() void ASimHUD::loadLevel() { if (AirSimSettings::singleton().level_name != "") - UAirBlueprintLib::RunCommandOnGameThread([&]() {UAirBlueprintLib::loadLevel(this->GetWorld(), FString(AirSimSettings::singleton().level_name.c_str()));}, true); + UAirBlueprintLib::RunCommandOnGameThread([&]() { UAirBlueprintLib::loadLevel(this->GetWorld(), FString(AirSimSettings::singleton().level_name.c_str())); }, true); else - UAirBlueprintLib::RunCommandOnGameThread([&]() {UAirBlueprintLib::loadLevel(this->GetWorld(), FString("Blocks"));}, true); + UAirBlueprintLib::RunCommandOnGameThread([&]() { UAirBlueprintLib::loadLevel(this->GetWorld(), FString("Blocks")); }, true); } void ASimHUD::createSimMode() { @@ -300,14 +295,17 @@ void ASimHUD::createSimMode() //spawn at origin. We will use this to do global NED transforms, for ex, non-vehicle objects in environment if (simmode_name == AirSimSettings::kSimModeTypeMultirotor) - simmode_ = this->GetWorld()->SpawnActor(FVector::ZeroVector, - FRotator::ZeroRotator, simmode_spawn_params); + simmode_ = this->GetWorld()->SpawnActor(FVector::ZeroVector, + FRotator::ZeroRotator, + simmode_spawn_params); else if (simmode_name == AirSimSettings::kSimModeTypeCar) simmode_ = this->GetWorld()->SpawnActor(FVector::ZeroVector, - FRotator::ZeroRotator, simmode_spawn_params); + FRotator::ZeroRotator, + simmode_spawn_params); else if (simmode_name == AirSimSettings::kSimModeTypeComputerVision) simmode_ = this->GetWorld()->SpawnActor(FVector::ZeroVector, - FRotator::ZeroRotator, simmode_spawn_params); + FRotator::ZeroRotator, + simmode_spawn_params); else { UAirBlueprintLib::ShowMessage(EAppMsgType::Ok, std::string("SimMode is not valid: ") + simmode_name, "Error"); UAirBlueprintLib::LogMessageString("SimMode is not valid: ", simmode_name, LogDebugLevel::Failure); @@ -344,38 +342,35 @@ void ASimHUD::initializeSubWindows() subwindow_cameras_[subwindow_setting.window_index] = vehicle_sim_api->getCamera(subwindow_setting.camera_name); else UAirBlueprintLib::LogMessageString("CameraID in element in settings.json is invalid", - std::to_string(window_index), LogDebugLevel::Failure); + std::to_string(window_index), + LogDebugLevel::Failure); } else UAirBlueprintLib::LogMessageString("Vehicle in element in settings.json is invalid", - std::to_string(window_index), LogDebugLevel::Failure); - + std::to_string(window_index), + LogDebugLevel::Failure); } - } FString ASimHUD::getLaunchPath(const std::string& filename) { FString launch_rel_path = FPaths::LaunchDir(); FString abs_path = FPaths::ConvertRelativePathToFull(launch_rel_path); - return FPaths::Combine(abs_path, FString(filename.c_str()) ); + return FPaths::Combine(abs_path, FString(filename.c_str())); } // Attempts to parse the settings text from one of multiple locations. // First, check the command line for settings provided via "-s" or "--settings" arguments // Next, check the executable's working directory for the settings file. -// Finally, check the user's documents folder. +// Finally, check the user's documents folder. // If the settings file cannot be read, throw an exception -bool ASimHUD::getSettingsText(std::string& settingsText) +bool ASimHUD::getSettingsText(std::string& settingsText) { - return (getSettingsTextFromCommandLine(settingsText) - || - readSettingsTextFromFile(FString(msr::airlib::Settings::getExecutableFullPath("settings.json").c_str()), settingsText) - || - readSettingsTextFromFile(getLaunchPath("settings.json"), settingsText) - || - readSettingsTextFromFile(FString(msr::airlib::Settings::Settings::getUserDirectoryFullPath("settings.json").c_str()), settingsText)); + return (getSettingsTextFromCommandLine(settingsText) || + readSettingsTextFromFile(FString(msr::airlib::Settings::getExecutableFullPath("settings.json").c_str()), settingsText) || + readSettingsTextFromFile(getLaunchPath("settings.json"), settingsText) || + readSettingsTextFromFile(FString(msr::airlib::Settings::Settings::getUserDirectoryFullPath("settings.json").c_str()), settingsText)); } // Attempts to parse the settings file path or the settings text from the command line @@ -383,7 +378,7 @@ bool ASimHUD::getSettingsText(std::string& settingsText) // Example (Path): AirSim.exe --settings "C:\path\to\settings.json" // Example (Text): AirSim.exe -s '{"foo" : "bar"}' -> settingsText will be set to {"foo": "bar"} // Returns true if the argument is present, false otherwise. -bool ASimHUD::getSettingsTextFromCommandLine(std::string& settingsText) +bool ASimHUD::getSettingsTextFromCommandLine(std::string& settingsText) { bool found = false; @@ -408,7 +403,7 @@ bool ASimHUD::getSettingsTextFromCommandLine(std::string& settingsText) return found; } -bool ASimHUD::readSettingsTextFromFile(const FString& settingsFilepath, std::string& settingsText) +bool ASimHUD::readSettingsTextFromFile(const FString& settingsFilepath, std::string& settingsText) { bool found = FPaths::FileExists(settingsFilepath); if (found) {