Adding functions to kill a pedestrian from the client library

This commit is contained in:
bernatx 2023-02-23 11:11:08 +01:00 committed by bernat
parent 73315d3d62
commit 44f0b8cd24
11 changed files with 83 additions and 0 deletions

View File

@ -88,6 +88,10 @@ namespace client {
GetEpisode().Lock()->SetActorCollisions(*this, enabled);
}
void Actor::SetActorDead() {
GetEpisode().Lock()->SetActorDead(*this);
}
void Actor::SetEnableGravity(const bool enabled) {
GetEpisode().Lock()->SetActorEnableGravity(*this, enabled);
}

View File

@ -102,6 +102,9 @@ namespace client {
/// Enable or disable collisions on this actor.
void SetCollisions(bool enabled = true);
/// Set actor as dead and starts his life span
void SetActorDead();
/// Enable or disable gravity on this actor.
void SetEnableGravity(bool enabled = true);

View File

@ -416,6 +416,10 @@ namespace detail {
_pimpl->CallAndWait<void>("set_actor_collisions", actor, enabled);
}
void Client::SetActorDead(rpc::ActorId actor) {
_pimpl->AsyncCall<void>("set_actor_dead", actor);
}
void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) {
_pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled);
}

View File

@ -240,6 +240,9 @@ namespace detail {
rpc::ActorId actor,
bool enabled);
void SetActorDead(
rpc::ActorId actor);
void SetActorEnableGravity(
rpc::ActorId actor,
bool enabled);

View File

@ -435,6 +435,10 @@ namespace detail {
_client.SetActorCollisions(actor.GetId(), enabled);
}
void SetActorDead(Actor &actor) {
_client.SetActorDead(actor.GetId());
}
void SetActorEnableGravity(Actor &actor, bool enabled) {
_client.SetActorEnableGravity(actor.GetId(), enabled);
}

View File

@ -66,6 +66,7 @@ namespace detail {
if (_nav.IsWalkerAlive(handle.walker, alive)) {
if (!alive) {
_client.SetActorCollisions(handle.walker, true);
_client.SetActorDead(handle.walker);
// remove from the crowd
_nav.RemoveAgent(handle.walker);
// destroy the controller

View File

@ -1454,3 +1454,26 @@ ECarlaServerResponse FWalkerActor::GetPoseFromAnimation()
}
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FWalkerActor::SetActorDead()
{
if (IsDormant())
{
}
else
{
auto Pawn = Cast<APawn>(GetActor());
if (Pawn == nullptr)
{
return ECarlaServerResponse::NotAWalker;
}
auto Walker = Cast<AWalkerBase>(Pawn);
if (Walker == nullptr)
{
return ECarlaServerResponse::NotAWalker;
}
Walker->StartDeathLifeSpan();
UE_LOG(LogCarla, Warning, TEXT("Walker starting life span by dead"));
}
return ECarlaServerResponse::Success;
}

View File

@ -415,6 +415,11 @@ public:
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse SetActorDead()
{
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse FreezeTrafficLight(bool)
{
return ECarlaServerResponse::ActorTypeMismatch;
@ -609,6 +614,8 @@ public:
virtual ECarlaServerResponse BlendPose(float Blend);
virtual ECarlaServerResponse GetPoseFromAnimation();
virtual ECarlaServerResponse SetActorDead();
};
class FOtherActor : public FCarlaActor

View File

@ -352,6 +352,8 @@ private:
bool SetActorCollisions(FCarlaActor &CarlaActor, bool bEnabled);
bool SetActorDead(FCarlaActor &CarlaActor);
void TickTimers(float DeltaSeconds)
{
ElapsedGameTime += DeltaSeconds;

View File

@ -1409,6 +1409,30 @@ void FCarlaServer::FPimpl::BindActions()
return R<void>::Success();
};
BIND_SYNC(set_actor_dead) << [this](
cr::ActorId ActorId) -> R<void>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"set_actor_dead",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
ECarlaServerResponse Response =
CarlaActor->SetActorDead();
if (Response != ECarlaServerResponse::Success)
{
return RespondError(
"set_actor_dead",
Response,
" Actor Id: " + FString::FromInt(ActorId));
}
return R<void>::Success();
};
BIND_SYNC(set_actor_enable_gravity) << [this](
cr::ActorId ActorId,
bool bEnabled) -> R<void>

View File

@ -21,4 +21,12 @@ public:
UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
bool bAlive = true;
UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere)
float AfterLifeSpan = 10.0f;
UFUNCTION(BlueprintCallable)
void StartDeathLifeSpan()
{
SetLifeSpan(AfterLifeSpan);
}
};