Rollback component serialization and updated querries to use the new components if possible
This commit is contained in:
parent
cbb0b711db
commit
40dc7bd7c5
|
@ -119,8 +119,6 @@ namespace detail {
|
|||
|
||||
geom::Vector3D acceleration;
|
||||
|
||||
uint32_t num_components;
|
||||
|
||||
union TypeDependentState {
|
||||
detail::TrafficLightData traffic_light_data;
|
||||
detail::VehicleData vehicle_data;
|
||||
|
@ -131,7 +129,7 @@ namespace detail {
|
|||
#pragma pack(pop)
|
||||
|
||||
static_assert(
|
||||
sizeof(ActorDynamicState) == 97u,
|
||||
sizeof(ActorDynamicState) == 93u,
|
||||
"Invalid ActorDynamicState size! "
|
||||
"If you modified this class please update the size here, else you may "
|
||||
"comment this assert, but your platform may have compatibility issues "
|
||||
|
|
|
@ -55,6 +55,7 @@ static auto FWorldObserver_GetActorState(const FActorView &View, const FActorReg
|
|||
|
||||
else if (AType::Walker == View.GetActorType())
|
||||
{
|
||||
UE_LOG(LogCarla, Warning, TEXT(" FWorldObserver_GetActorState Walker"));
|
||||
auto Walker = Cast<APawn>(View.GetActor());
|
||||
auto Controller = Walker != nullptr ? Cast<AWalkerController>(Walker->GetController()) : nullptr;
|
||||
if (Controller != nullptr)
|
||||
|
@ -68,11 +69,13 @@ static auto FWorldObserver_GetActorState(const FActorView &View, const FActorReg
|
|||
if (TrafficLight != nullptr)
|
||||
{
|
||||
|
||||
UActorComponent* TrafficLightComponent = TrafficLight->FindComponentByClass<UTrafficLightComponent>();
|
||||
UTrafficLightComponent* TrafficLightComponent =
|
||||
Cast<UTrafficLightComponent>(TrafficLight->FindComponentByClass<UTrafficLightComponent>());
|
||||
|
||||
using TLS = carla::rpc::TrafficLightState;
|
||||
|
||||
if(TrafficLightComponent == nullptr) {
|
||||
// Old way: traffic lights are actors
|
||||
using TLS = carla::rpc::TrafficLightState;
|
||||
state.traffic_light_data.state = static_cast<TLS>(TrafficLight->GetTrafficLightState());
|
||||
state.traffic_light_data.green_time = TrafficLight->GetGreenTime();
|
||||
state.traffic_light_data.yellow_time = TrafficLight->GetYellowTime();
|
||||
|
@ -80,6 +83,18 @@ static auto FWorldObserver_GetActorState(const FActorView &View, const FActorReg
|
|||
state.traffic_light_data.elapsed_time = TrafficLight->GetElapsedTime();
|
||||
state.traffic_light_data.time_is_frozen = TrafficLight->GetTimeIsFrozen();
|
||||
state.traffic_light_data.pole_index = TrafficLight->GetPoleIndex();
|
||||
} else {
|
||||
UTrafficLightController* Controller = TrafficLightComponent->GetController();
|
||||
ATrafficLightGroup* Group = TrafficLightComponent->GetGroup();
|
||||
|
||||
state.traffic_light_data.state = static_cast<TLS>(TrafficLightComponent->GetLightState());
|
||||
state.traffic_light_data.green_time = Controller->GetGreenTime();
|
||||
state.traffic_light_data.yellow_time = Controller->GetYellowTime();
|
||||
state.traffic_light_data.red_time = Controller->GetRedTime();
|
||||
state.traffic_light_data.elapsed_time = Group->GetElapsedTime();
|
||||
state.traffic_light_data.time_is_frozen = Group->IsFrozen();
|
||||
// Nobody is using this right now, perhaps we should remove it?
|
||||
state.traffic_light_data.pole_index = TrafficLight->GetPoleIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,25 +207,9 @@ static carla::Buffer FWorldObserver_Serialize(
|
|||
carla::geom::Vector3D{Velocity.X, Velocity.Y, Velocity.Z},
|
||||
FWorldObserver_GetAngularVelocity(*View.GetActor()),
|
||||
FWorldObserver_GetAcceleration(View, Velocity, DeltaSeconds),
|
||||
0,
|
||||
FWorldObserver_GetActorState(View, Registry),
|
||||
};
|
||||
|
||||
TArray<ComponentDynamicState> ComponentsState;
|
||||
FWorldObserver_GetActorComponentsState(View, Registry, ComponentsState);
|
||||
info.num_components = ComponentsState.Num();
|
||||
|
||||
write_data(info);
|
||||
|
||||
if(info.num_components > 0) {
|
||||
total_size += info.num_components * sizeof(ComponentDynamicState);
|
||||
buffer.resize(total_size);
|
||||
|
||||
for(auto& CompState : ComponentsState)
|
||||
{
|
||||
write_data(CompState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shrink buffer
|
||||
|
|
|
@ -105,6 +105,12 @@ void ATrafficLightBase::PostEditChangeProperty(FPropertyChangedEvent &Event)
|
|||
|
||||
void ATrafficLightBase::SetTrafficLightState(const ETrafficLightState InState)
|
||||
{
|
||||
UTrafficLightComponent* TrafficLightComponent =
|
||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
||||
|
||||
if(TrafficLightComponent) {
|
||||
TrafficLightComponent->SetLightState(InState);
|
||||
} else {
|
||||
ElapsedTime = 0.0f;
|
||||
State = InState;
|
||||
SetTrafficSignState(ToTrafficSignState(State));
|
||||
|
@ -123,6 +129,7 @@ void ATrafficLightBase::SetTrafficLightState(const ETrafficLightState InState)
|
|||
{
|
||||
Vehicles.Empty();
|
||||
}
|
||||
}
|
||||
OnTrafficLightStateChanged(State);
|
||||
}
|
||||
|
||||
|
@ -178,7 +185,18 @@ void ATrafficLightBase::UnNotifyWheeledVehicle(ACarlaWheeledVehicle *Vehicle)
|
|||
|
||||
void ATrafficLightBase::SetGreenTime(float InGreenTime)
|
||||
{
|
||||
UTrafficLightComponent* TrafficLightComponent =
|
||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
||||
|
||||
if(TrafficLightComponent) {
|
||||
UTrafficLightController* TrafficLightController =
|
||||
TrafficLightComponent->GetController();
|
||||
check(TrafficLightController)
|
||||
TrafficLightController->SetGreenTime(InGreenTime);
|
||||
|
||||
} else {
|
||||
GreenTime = InGreenTime;
|
||||
}
|
||||
}
|
||||
|
||||
float ATrafficLightBase::GetGreenTime() const
|
||||
|
@ -188,7 +206,17 @@ float ATrafficLightBase::GetGreenTime() const
|
|||
|
||||
void ATrafficLightBase::SetYellowTime(float InYellowTime)
|
||||
{
|
||||
UTrafficLightComponent* TrafficLightComponent =
|
||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
||||
|
||||
if(TrafficLightComponent) {
|
||||
UTrafficLightController* TrafficLightController =
|
||||
TrafficLightComponent->GetController();
|
||||
check(TrafficLightController)
|
||||
TrafficLightController->SetYellowTime(InYellowTime);
|
||||
} else {
|
||||
YellowTime = InYellowTime;
|
||||
}
|
||||
}
|
||||
|
||||
float ATrafficLightBase::GetYellowTime() const
|
||||
|
@ -198,7 +226,17 @@ float ATrafficLightBase::GetYellowTime() const
|
|||
|
||||
void ATrafficLightBase::SetRedTime(float InRedTime)
|
||||
{
|
||||
UTrafficLightComponent* TrafficLightComponent =
|
||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
||||
|
||||
if(TrafficLightComponent) {
|
||||
UTrafficLightController* TrafficLightController =
|
||||
TrafficLightComponent->GetController();
|
||||
check(TrafficLightController)
|
||||
TrafficLightController->SetRedTime(InRedTime);
|
||||
} else {
|
||||
RedTime = InRedTime;
|
||||
}
|
||||
}
|
||||
|
||||
float ATrafficLightBase::GetRedTime() const
|
||||
|
@ -218,11 +256,18 @@ void ATrafficLightBase::SetElapsedTime(float InElapsedTime)
|
|||
|
||||
void ATrafficLightBase::SetTimeIsFrozen(bool InTimeIsFrozen)
|
||||
{
|
||||
UTrafficLightComponent* TrafficLightComponent =
|
||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
||||
|
||||
if(TrafficLightComponent) {
|
||||
TrafficLightComponent->SetFrozenGroup(InTimeIsFrozen);
|
||||
} else {
|
||||
TimeIsFrozen = InTimeIsFrozen;
|
||||
if (!TimeIsFrozen)
|
||||
{
|
||||
ElapsedTime = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ATrafficLightBase::GetTimeIsFrozen() const
|
||||
|
@ -242,6 +287,22 @@ int ATrafficLightBase::GetPoleIndex() const
|
|||
|
||||
TArray<ATrafficLightBase *> ATrafficLightBase::GetGroupTrafficLights() const
|
||||
{
|
||||
UTrafficLightComponent* TrafficLightComponent =
|
||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
||||
|
||||
if(TrafficLightComponent) {
|
||||
TArray<ATrafficLightBase *> result;
|
||||
UTrafficLightController* TrafficLightController =
|
||||
TrafficLightComponent->GetController();
|
||||
check(TrafficLightController)
|
||||
|
||||
for(auto& TLComp : TrafficLightController->GetTrafficLights())
|
||||
{
|
||||
result.Add(Cast<ATrafficLightBase>(GetOwner()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return GroupTrafficLights;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,21 @@ void UTrafficLightController::ResetState()
|
|||
SetTrafficLightsState(GetCurrentState().State);
|
||||
}
|
||||
|
||||
void UTrafficLightController::SetYellowTime(float NewTime)
|
||||
{
|
||||
SetStateTime(ETrafficLightState::Yellow, NewTime);
|
||||
}
|
||||
|
||||
void UTrafficLightController::SetRedTime(float NewTime)
|
||||
{
|
||||
SetStateTime(ETrafficLightState::Red, NewTime);
|
||||
}
|
||||
|
||||
void UTrafficLightController::SetGreenTime(float NewTime)
|
||||
{
|
||||
SetStateTime(ETrafficLightState::Green, NewTime);
|
||||
}
|
||||
|
||||
float UTrafficLightController::GetGreenTime() const
|
||||
{
|
||||
return GetStateTime(ETrafficLightState::Green);
|
||||
|
@ -93,6 +108,17 @@ float UTrafficLightController::GetRedTime() const
|
|||
return GetStateTime(ETrafficLightState::Red);
|
||||
}
|
||||
|
||||
void UTrafficLightController::SetStateTime(const ETrafficLightState State, float NewTime)
|
||||
{
|
||||
for(auto& LightState : LightStates)
|
||||
{
|
||||
if(LightState.State == State)
|
||||
{
|
||||
LightState.Time = NewTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float UTrafficLightController::GetStateTime(const ETrafficLightState State) const
|
||||
{
|
||||
for(auto& LightState : LightStates)
|
||||
|
|
|
@ -75,6 +75,15 @@ public:
|
|||
UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
|
||||
void ResetState();
|
||||
|
||||
UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
|
||||
void SetYellowTime(float NewTime);
|
||||
|
||||
UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
|
||||
void SetRedTime(float NewTime);
|
||||
|
||||
UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
|
||||
void SetGreenTime(float NewTime);
|
||||
|
||||
UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
|
||||
float GetGreenTime() const;
|
||||
|
||||
|
@ -84,8 +93,11 @@ public:
|
|||
UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
|
||||
float GetRedTime() const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void SetStateTime(const ETrafficLightState State, float NewTime);
|
||||
|
||||
float GetStateTime(const ETrafficLightState State) const;
|
||||
|
||||
UPROPERTY(Category = "Traffic Controller", EditAnywhere)
|
||||
|
|
Loading…
Reference in New Issue