Fixed server-client sincronization for map change.

This commit is contained in:
Axel1092 2020-04-22 12:00:13 +02:00 committed by bernat
parent 953a86d62a
commit ff97d65cc0
5 changed files with 31 additions and 3 deletions

View File

@ -145,6 +145,10 @@ namespace detail {
_pimpl->CallAndWait<void>("load_new_episode", std::move(map_name));
}
bool Client::CheckIntermediateEpisode() {
return _pimpl->CallAndWait<bool>("check_intermediate_episode");
}
void Client::CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters & params) {
// Await response, we need to be sure in this one.
_pimpl->CallAndWait<void>("copy_opendrive_to_file", std::move(opendrive), params);

View File

@ -88,6 +88,8 @@ namespace detail {
void LoadEpisode(std::string map_name);
bool CheckIntermediateEpisode();
void CopyOpenDriveToServer(
std::string opendrive, const rpc::OpendriveGenerationParameters & params);

View File

@ -90,7 +90,7 @@ namespace detail {
using namespace std::literals::chrono_literals;
_episode->WaitForState(10ms);
auto episode = GetCurrentEpisode();
if (episode.GetId() != id) {
if (episode.GetId() != id && !_client.CheckIntermediateEpisode()) {
return episode;
}
}

View File

@ -87,6 +87,10 @@ public:
void CheckAndLoadMap(UWorld *world, UCarlaEpisode &Episode);
bool IsLevelPendingLoad() const {
return bShouldLoadLevel;
}
private:
UPROPERTY(Category = "CARLA Settings", EditAnywhere)

View File

@ -228,14 +228,32 @@ void FCarlaServer::FPimpl::BindActions()
BIND_SYNC(load_new_episode) << [this](const std::string &map_name) -> R<void>
{
REQUIRE_CARLA_EPISODE();
UCarlaStatics::GetGameInstance(Episode->GetWorld())->SetMapToLoad(cr::ToFString(map_name));
if (!Episode->LoadNewEpisode(cr::ToFString("OpendriveMap")))
FString MapName = cr::ToFString(map_name);
auto Maps = UCarlaStatics::GetAllMapNames();
bool bMissingMap = true;
for (auto & Map : Maps)
{
if(Map.Contains(MapName))
{
bMissingMap = false;
break;
}
}
if(bMissingMap)
{
RESPOND_ERROR("map not found");
}
UCarlaStatics::GetGameInstance(Episode->GetWorld())->SetMapToLoad(MapName);
Episode->LoadNewEpisode(cr::ToFString("EmptyMap"));
return R<void>::Success();
};
BIND_SYNC(check_intermediate_episode) << [this]() -> R<bool>
{
REQUIRE_CARLA_EPISODE();
return UCarlaStatics::GetGameInstance(Episode->GetWorld())->IsLevelPendingLoad();
};
BIND_SYNC(copy_opendrive_to_file) << [this](const std::string &opendrive, carla::rpc::OpendriveGenerationParameters Params) -> R<void>
{
REQUIRE_CARLA_EPISODE();