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);
|
||||
|
||||
if (FPaths::FileExists(FinalPath)) {
|
||||
UCarlaStatics::GetGameInstance(GetWorld())->SetMapPath(FinalPath);
|
||||
bIsFileFound = true;
|
||||
FinalPath = MapString;
|
||||
}
|
||||
|
@ -90,7 +89,7 @@ bool UCarlaEpisode::LoadNewEpisode(const FString &MapString, bool ResetSettings)
|
|||
FinalPath = TempStrArray[1];
|
||||
FinalPath.ParseIntoArray(TempStrArray, TEXT("."), true);
|
||||
FinalPath = "/Game/" + TempStrArray[0];
|
||||
|
||||
|
||||
return LoadNewEpisode(FinalPath, ResetSettings);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,12 +13,10 @@ UCarlaGameInstance::UCarlaGameInstance() {
|
|||
CarlaSettings = CreateDefaultSubobject<UCarlaSettings>(TEXT("CarlaSettings"));
|
||||
Recorder = CreateDefaultSubobject<ACarlaRecorder>(TEXT("Recorder"));
|
||||
CarlaEngine.SetRecorder(Recorder);
|
||||
|
||||
|
||||
check(CarlaSettings != nullptr);
|
||||
CarlaSettings->LoadSettings();
|
||||
CarlaSettings->LogSettings();
|
||||
|
||||
SetDefaultMapPath();
|
||||
}
|
||||
|
||||
UCarlaGameInstance::~UCarlaGameInstance() = default;
|
||||
|
|
|
@ -103,40 +103,6 @@ public:
|
|||
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:
|
||||
|
||||
UPROPERTY(Category = "CARLA Settings", EditAnywhere)
|
||||
|
|
|
@ -50,6 +50,13 @@ ACarlaGameModeBase::ACarlaGameModeBase(const FObjectInitializer& ObjectInitializ
|
|||
CarlaSettingsDelegate = CreateDefaultSubobject<UCarlaSettingsDelegate>(TEXT("CarlaSettingsDelegate"));
|
||||
}
|
||||
|
||||
const FString ACarlaGameModeBase::GetMapPath() const
|
||||
{
|
||||
UWorld* World = GetWorld();
|
||||
TSoftObjectPtr<UWorld> AssetPtr (World);
|
||||
return AssetPtr.GetLongPackageName();
|
||||
}
|
||||
|
||||
void ACarlaGameModeBase::InitGame(
|
||||
const FString &MapName,
|
||||
const FString &Options,
|
||||
|
|
|
@ -48,6 +48,8 @@ public:
|
|||
return Map;
|
||||
}
|
||||
|
||||
const FString GetMapPath() const;
|
||||
|
||||
UFUNCTION(Exec, Category = "CARLA Game Mode")
|
||||
void DebugShowSignals(bool enable);
|
||||
|
||||
|
@ -164,7 +166,7 @@ private:
|
|||
|
||||
bool ReadyToRegisterObjects = false;
|
||||
|
||||
// We keep a global uuid to allow the load/unload layer methods to be called
|
||||
// We keep a global uuid to allow the load/unload layer methods to be called
|
||||
// in the same tick
|
||||
int32 LatentInfoUUID = 0;
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "Carla.h"
|
||||
#include "Carla/OpenDrive/OpenDrive.h"
|
||||
#include "Carla/Game/CarlaGameModeBase.h"
|
||||
#include "GenericPlatform/GenericPlatformProcess.h"
|
||||
|
||||
#include "Runtime/Core/Public/HAL/FileManagerGeneric.h"
|
||||
|
||||
|
@ -66,7 +68,11 @@ FString UOpenDrive::GetXODR(const UWorld *World)
|
|||
}
|
||||
#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 FileName = MapDir.EndsWith(MapName) ? "*" : MapName;
|
||||
|
||||
|
|
|
@ -341,8 +341,9 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
BIND_SYNC(get_map_info) << [this]() -> R<cr::MapInfo>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
|
||||
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);
|
||||
MapDir += "/" + Episode->GetMapName();
|
||||
return cr::MapInfo{
|
||||
|
@ -353,7 +354,7 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
BIND_SYNC(get_map_data) << [this]() -> R<std::string>
|
||||
{
|
||||
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>>
|
||||
|
@ -376,7 +377,8 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
}
|
||||
|
||||
// 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 fileName = mapDir.EndsWith(Episode->GetMapName()) ? "*" : Episode->GetMapName();
|
||||
|
||||
|
|
Loading…
Reference in New Issue