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)); _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) { void Client::CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters & params) {
// Await response, we need to be sure in this one. // Await response, we need to be sure in this one.
_pimpl->CallAndWait<void>("copy_opendrive_to_file", std::move(opendrive), params); _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); void LoadEpisode(std::string map_name);
bool CheckIntermediateEpisode();
void CopyOpenDriveToServer( void CopyOpenDriveToServer(
std::string opendrive, const rpc::OpendriveGenerationParameters & params); std::string opendrive, const rpc::OpendriveGenerationParameters & params);

View File

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

View File

@ -87,6 +87,10 @@ public:
void CheckAndLoadMap(UWorld *world, UCarlaEpisode &Episode); void CheckAndLoadMap(UWorld *world, UCarlaEpisode &Episode);
bool IsLevelPendingLoad() const {
return bShouldLoadLevel;
}
private: private:
UPROPERTY(Category = "CARLA Settings", EditAnywhere) 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> BIND_SYNC(load_new_episode) << [this](const std::string &map_name) -> R<void>
{ {
REQUIRE_CARLA_EPISODE(); REQUIRE_CARLA_EPISODE();
UCarlaStatics::GetGameInstance(Episode->GetWorld())->SetMapToLoad(cr::ToFString(map_name)); FString MapName = cr::ToFString(map_name);
if (!Episode->LoadNewEpisode(cr::ToFString("OpendriveMap"))) 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"); RESPOND_ERROR("map not found");
} }
UCarlaStatics::GetGameInstance(Episode->GetWorld())->SetMapToLoad(MapName);
Episode->LoadNewEpisode(cr::ToFString("EmptyMap"));
return R<void>::Success(); 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> BIND_SYNC(copy_opendrive_to_file) << [this](const std::string &opendrive, carla::rpc::OpendriveGenerationParameters Params) -> R<void>
{ {
REQUIRE_CARLA_EPISODE(); REQUIRE_CARLA_EPISODE();