Fixed load xodr file from UWorld
This commit is contained in:
parent
c269c7efb4
commit
fb30cbafac
|
@ -71,7 +71,6 @@ bool UCarlaEpisode::LoadNewEpisode(const FString &MapString, bool ResetSettings)
|
||||||
FinalPath = IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FinalPath);
|
FinalPath = IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FinalPath);
|
||||||
|
|
||||||
if (FPaths::FileExists(FinalPath)) {
|
if (FPaths::FileExists(FinalPath)) {
|
||||||
UCarlaStatics::GetGameInstance(GetWorld())->SetMapPath(FinalPath);
|
|
||||||
bIsFileFound = true;
|
bIsFileFound = true;
|
||||||
FinalPath = MapString;
|
FinalPath = MapString;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@ UCarlaGameInstance::UCarlaGameInstance() {
|
||||||
check(CarlaSettings != nullptr);
|
check(CarlaSettings != nullptr);
|
||||||
CarlaSettings->LoadSettings();
|
CarlaSettings->LoadSettings();
|
||||||
CarlaSettings->LogSettings();
|
CarlaSettings->LogSettings();
|
||||||
|
|
||||||
SetDefaultMapPath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UCarlaGameInstance::~UCarlaGameInstance() = default;
|
UCarlaGameInstance::~UCarlaGameInstance() = default;
|
||||||
|
|
|
@ -103,40 +103,6 @@ public:
|
||||||
return CurrentMapLayer;
|
return CurrentMapLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable)
|
|
||||||
void SetDefaultMapPath() {
|
|
||||||
// Read the config file
|
|
||||||
FConfigFile ConfigFile = FConfigFile();
|
|
||||||
FString configFStr = FPaths::ProjectDir();
|
|
||||||
configFStr += "Config/DefaultEngine.ini";
|
|
||||||
ConfigFile.Read(configFStr);
|
|
||||||
|
|
||||||
// Depending on where we are, set the editor or game default map
|
|
||||||
#ifdef UE_EDITOR
|
|
||||||
ConfigFile.GetString(TEXT("/Script/EngineSettings.GameMapsSettings"), TEXT("EditorStartupMap"), _MapPath);
|
|
||||||
#else
|
|
||||||
ConfigFile.GetString(TEXT("/Script/EngineSettings.GameMapsSettings"), TEXT("GameDefaultMap"), _MapPath);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Format and convert the path to absolute
|
|
||||||
_MapPath.RemoveFromStart(TEXT("/Game/"));
|
|
||||||
_MapPath = FPaths::ProjectContentDir() + _MapPath;
|
|
||||||
_MapPath = IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*_MapPath);
|
|
||||||
_MapPath = FPaths::GetBaseFilename(_MapPath, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable)
|
|
||||||
void SetMapPath(const FString &MapPath)
|
|
||||||
{
|
|
||||||
_MapPath = MapPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable)
|
|
||||||
const FString &GetMapPath() const
|
|
||||||
{
|
|
||||||
return _MapPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY(Category = "CARLA Settings", EditAnywhere)
|
UPROPERTY(Category = "CARLA Settings", EditAnywhere)
|
||||||
|
|
|
@ -50,6 +50,13 @@ ACarlaGameModeBase::ACarlaGameModeBase(const FObjectInitializer& ObjectInitializ
|
||||||
CarlaSettingsDelegate = CreateDefaultSubobject<UCarlaSettingsDelegate>(TEXT("CarlaSettingsDelegate"));
|
CarlaSettingsDelegate = CreateDefaultSubobject<UCarlaSettingsDelegate>(TEXT("CarlaSettingsDelegate"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FString ACarlaGameModeBase::GetMapPath() const
|
||||||
|
{
|
||||||
|
UWorld* World = GetWorld();
|
||||||
|
TSoftObjectPtr<UWorld> AssetPtr (World);
|
||||||
|
return AssetPtr.GetLongPackageName();
|
||||||
|
}
|
||||||
|
|
||||||
void ACarlaGameModeBase::InitGame(
|
void ACarlaGameModeBase::InitGame(
|
||||||
const FString &MapName,
|
const FString &MapName,
|
||||||
const FString &Options,
|
const FString &Options,
|
||||||
|
|
|
@ -48,6 +48,8 @@ public:
|
||||||
return Map;
|
return Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FString GetMapPath() const;
|
||||||
|
|
||||||
UFUNCTION(Exec, Category = "CARLA Game Mode")
|
UFUNCTION(Exec, Category = "CARLA Game Mode")
|
||||||
void DebugShowSignals(bool enable);
|
void DebugShowSignals(bool enable);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include "Carla.h"
|
#include "Carla.h"
|
||||||
#include "Carla/OpenDrive/OpenDrive.h"
|
#include "Carla/OpenDrive/OpenDrive.h"
|
||||||
|
#include "Carla/Game/CarlaGameModeBase.h"
|
||||||
|
#include "GenericPlatform/GenericPlatformProcess.h"
|
||||||
|
|
||||||
#include "Runtime/Core/Public/HAL/FileManagerGeneric.h"
|
#include "Runtime/Core/Public/HAL/FileManagerGeneric.h"
|
||||||
|
|
||||||
|
@ -66,7 +68,11 @@ FString UOpenDrive::GetXODR(const UWorld *World)
|
||||||
}
|
}
|
||||||
#endif // WITH_EDITOR
|
#endif // WITH_EDITOR
|
||||||
|
|
||||||
const auto MapDir = FPaths::GetPath(UCarlaStatics::GetGameInstance(World)->GetMapPath());
|
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(World);
|
||||||
|
|
||||||
|
auto RelativePath = FPaths::GetPath(GameMode->GetMapPath());
|
||||||
|
RelativePath.RemoveFromStart("/Game/");
|
||||||
|
auto MapDir = FPaths::ProjectContentDir() + RelativePath;
|
||||||
const auto FolderDir = MapDir + "/OpenDrive/";
|
const auto FolderDir = MapDir + "/OpenDrive/";
|
||||||
const auto FileName = MapDir.EndsWith(MapName) ? "*" : MapName;
|
const auto FileName = MapDir.EndsWith(MapName) ? "*" : MapName;
|
||||||
|
|
||||||
|
|
|
@ -341,8 +341,9 @@ void FCarlaServer::FPimpl::BindActions()
|
||||||
BIND_SYNC(get_map_info) << [this]() -> R<cr::MapInfo>
|
BIND_SYNC(get_map_info) << [this]() -> R<cr::MapInfo>
|
||||||
{
|
{
|
||||||
REQUIRE_CARLA_EPISODE();
|
REQUIRE_CARLA_EPISODE();
|
||||||
|
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
|
||||||
const auto &SpawnPoints = Episode->GetRecommendedSpawnPoints();
|
const auto &SpawnPoints = Episode->GetRecommendedSpawnPoints();
|
||||||
FString FullMapPath = FPaths::GetPath(UCarlaStatics::GetGameInstance(Episode->GetWorld())->GetMapPath());
|
FString FullMapPath = FPaths::GetPath(GameMode->GetMapPath());
|
||||||
FString MapDir = FullMapPath.RightChop(FullMapPath.Find("Content/", ESearchCase::CaseSensitive) + 8);
|
FString MapDir = FullMapPath.RightChop(FullMapPath.Find("Content/", ESearchCase::CaseSensitive) + 8);
|
||||||
MapDir += "/" + Episode->GetMapName();
|
MapDir += "/" + Episode->GetMapName();
|
||||||
return cr::MapInfo{
|
return cr::MapInfo{
|
||||||
|
@ -353,7 +354,7 @@ void FCarlaServer::FPimpl::BindActions()
|
||||||
BIND_SYNC(get_map_data) << [this]() -> R<std::string>
|
BIND_SYNC(get_map_data) << [this]() -> R<std::string>
|
||||||
{
|
{
|
||||||
REQUIRE_CARLA_EPISODE();
|
REQUIRE_CARLA_EPISODE();
|
||||||
return cr::FromFString(UOpenDrive::GetXODR(Episode->GetWorld()));
|
return cr::FromLongFString(UOpenDrive::GetXODR(Episode->GetWorld()));
|
||||||
};
|
};
|
||||||
|
|
||||||
BIND_SYNC(get_navigation_mesh) << [this]() -> R<std::vector<uint8_t>>
|
BIND_SYNC(get_navigation_mesh) << [this]() -> R<std::vector<uint8_t>>
|
||||||
|
@ -376,7 +377,8 @@ void FCarlaServer::FPimpl::BindActions()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the map's folder absolute path and check if it's in its own folder
|
// Get the map's folder absolute path and check if it's in its own folder
|
||||||
const auto mapDir = FPaths::GetPath(UCarlaStatics::GetGameInstance(Episode->GetWorld())->GetMapPath());
|
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
|
||||||
|
const auto mapDir = FPaths::GetPath(GameMode->GetMapPath());
|
||||||
const auto folderDir = mapDir + "/" + folder.c_str();
|
const auto folderDir = mapDir + "/" + folder.c_str();
|
||||||
const auto fileName = mapDir.EndsWith(Episode->GetMapName()) ? "*" : Episode->GetMapName();
|
const auto fileName = mapDir.EndsWith(Episode->GetMapName()) ? "*" : Episode->GetMapName();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue