Fix some issues when loading the carla settings that the client sent

This commit is contained in:
nsubiron 2017-05-30 10:49:58 +01:00
parent c38f39147f
commit 2951d24545
2 changed files with 20 additions and 9 deletions

View File

@ -76,13 +76,18 @@ static bool RequestedSemanticSegmentation(const FCameraDescription &Camera)
return (Camera.PostProcessEffect == EPostProcessEffect::SemanticSegmentation); return (Camera.PostProcessEffect == EPostProcessEffect::SemanticSegmentation);
} }
static void LoadSettingsFromConfig(const MyIniFile &ConfigFile, UCarlaSettings &Settings) static void LoadSettingsFromConfig(
const MyIniFile &ConfigFile,
UCarlaSettings &Settings,
const bool bLoadCarlaServerSection)
{ {
// CarlaServer. // CarlaServer.
ConfigFile.GetBool(S_CARLA_SERVER, TEXT("UseNetworking"), Settings.bUseNetworking); if (bLoadCarlaServerSection) {
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WorldPort"), Settings.WorldPort); ConfigFile.GetBool(S_CARLA_SERVER, TEXT("UseNetworking"), Settings.bUseNetworking);
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WritePort"), Settings.WritePort); ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WorldPort"), Settings.WorldPort);
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("ReadPort"), Settings.ReadPort); ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WritePort"), Settings.WritePort);
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("ReadPort"), Settings.ReadPort);
}
// LevelSettings. // LevelSettings.
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("NumberOfVehicles"), Settings.NumberOfVehicles); ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("NumberOfVehicles"), Settings.NumberOfVehicles);
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("NumberOfPedestrians"), Settings.NumberOfPedestrians); ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("NumberOfPedestrians"), Settings.NumberOfPedestrians);
@ -148,7 +153,7 @@ void UCarlaSettings::LoadSettings()
if (GetSettingsFileName(FileName)) { if (GetSettingsFileName(FileName)) {
UE_LOG(LogCarla, Log, TEXT("Loading settings from \"%s\""), *FileName); UE_LOG(LogCarla, Log, TEXT("Loading settings from \"%s\""), *FileName);
const MyIniFile ConfigFile(FileName); const MyIniFile ConfigFile(FileName);
LoadSettingsFromConfig(ConfigFile, *this); LoadSettingsFromConfig(ConfigFile, *this, true);
CurrentFileName = FileName; CurrentFileName = FileName;
} else { } else {
CurrentFileName = TEXT(""); CurrentFileName = TEXT("");
@ -162,11 +167,17 @@ void UCarlaSettings::LoadSettings()
} }
} }
void UCarlaSettings::LoadSettingsFromString(const FString &INIFileContents) void UCarlaSettings::LoadSettingsFromString(
const FString &INIFileContents,
const bool bLoadCarlaServerSection)
{ {
// Reset cameras.
CameraDescriptions.Empty();
bSemanticSegmentationEnabled = false;
// Load config from string.
MyIniFile ConfigFile; MyIniFile ConfigFile;
ConfigFile.ProcessInputFileContents(INIFileContents); ConfigFile.ProcessInputFileContents(INIFileContents);
LoadSettingsFromConfig(ConfigFile, *this); LoadSettingsFromConfig(ConfigFile, *this, bLoadCarlaServerSection);
} }
void UCarlaSettings::LogSettings() const void UCarlaSettings::LogSettings() const

View File

@ -20,7 +20,7 @@ public:
void LoadSettings(); void LoadSettings();
/** Load the settings from the given string (formatted as INI). */ /** Load the settings from the given string (formatted as INI). */
void LoadSettingsFromString(const FString &INIFileContents); void LoadSettingsFromString(const FString &INIFileContents, bool bLoadCarlaServerSection = false);
/** Log settings values. */ /** Log settings values. */
void LogSettings() const; void LogSettings() const;