Allow destroying actors from Python

This commit is contained in:
nsubiron 2018-07-28 13:04:59 +02:00
parent 67643485cc
commit f9b7578d6c
6 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,18 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "carla/client/Actor.h"
#include "carla/client/Client.h"
namespace carla {
namespace client {
void Actor::Destroy() {
GetWorld()->GetClient().DestroyActor(*this);
}
} // namespace client
} // namespace carla

View File

@ -43,6 +43,8 @@ namespace client {
return _actor;
}
void Destroy();
protected:
Actor(carla::rpc::Actor actor, SharedPtr<World> world)

View File

@ -35,6 +35,10 @@ namespace client {
return SharedPtr<Actor>(new Vehicle{actor, GetWorld()});
}
void Client::DestroyActor(Actor &actor) {
_client.call("destroy_actor", actor.Serialize());
}
void Client::ApplyControlToActor(
const Actor &actor,
const VehicleControl &control) {

View File

@ -76,6 +76,8 @@ namespace client {
const Transform &transform,
Actor *parent = nullptr);
void DestroyActor(Actor &actor);
void ApplyControlToActor(
const Actor &actor,
const VehicleControl &control);

View File

@ -79,6 +79,7 @@ void export_actor() {
return self.GetTypeId();
})
.def("get_world", &cc::Actor::GetWorld)
.def("destroy", &cc::Actor::Destroy)
.def(self_ns::str(self_ns::self))
;

View File

@ -185,6 +185,15 @@ void FTheNewCarlaServer::FPimpl::BindActions()
return SerializeActor(ActorView);
});
Server.BindSync("destroy_actor", [this](cr::Actor Actor) {
RequireEpisode();
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
RespondErrorStr("unable to destroy actor: actor not found");
}
Episode->DestroyActor(ActorView.GetActor());
});
Server.BindSync("attach_actors", [this](cr::Actor Child, cr::Actor Parent) {
RequireEpisode();
auto &Registry = Episode->GetActorRegistry();